Drupal 6.x clean urls with lighttpd 1.4 + windows 7
Posted by bollysite on August 1st, 2010While experimenting with drupal module development on my lighttpd server (Windows 7 Ultimate), I encounter some wired things.
- It stuck on installation page, after taking mysql host, username and password, nothing happened…
SOLUTION:
I changed permission of sites/default/settings.php & supplied mysql credentials manually. So it moved to next steps and completed installation.
- Okay… trouble were not just over. After completing installation, when I went to admin”/settings/clean-urls”I realized lighttpd + drupal + windows = Trouble to developer!

- Clean URL option was disabled! I couldn’t change it (although I could do it with firefox developer toolbar). So I started searching the drupal community for lighttpd rules. Bunch of pages had number of answers like mod_magnet, lua, mod_rewrite and blah .. blah.. Windows 7 and centos 5.0 have some trouble with lua and mod_magnet so I had to takeĀ mod_rewrite option.
SOLUTION:
It did trick when I took code from other site and paste it into settings.php I could able to enable option with the code.if (strpos($_SERVER['SERVER_SOFTWARE'], 'LightTPD') !== false) { $_lighty_url = $base_url.$_SERVER['REQUEST_URI']; $_lighty_url = @parse_url($_lighty_url); if ($_lighty_url['path'] != '/index.php' && $_lighty_url['path'] != '/') { $_SERVER['QUERY_STRING'] = $_lighty_url['path']; parse_str($_lighty_url['path'], $_lighty_query); foreach ($_lighty_query as $key => $val) $_GET[$key] = $_REQUEST[$key] = $val; } $_GET['q'] = $_REQUEST['q'] = substr($_lighty_url['path'], 1); } }but I didn’t know, blind copy paste will make things much uneasier.
- While reading drupal view module documents, I figured out I can save my lots of time in most of the projects. So I installed view module and tried to enable frontpage module by clicking enable link inside admin/build/views. But I got the classic 403 error “You are not authorized to access this page.” I tried to search, for the same but couldn’t find the solution anywhere.
So, I open that core module, and checked for the error function in /modules/views/includes/admin.inc and I found that…
/** * Page callback for the Views enable page. */ function views_ui_enable_page($view) { if (isset($_GET['token']) && drupal_valid_token($_GET['token'], 'views-enable')) { $views_status = variable_get('views_defaults', array()); $views_status[$view->name] = FALSE; // false is enabled variable_set('views_defaults', $views_status); views_invalidate_cache(); menu_rebuild(); drupal_goto('admin/build/views'); } else { return drupal_access_denied(); } }was creating the problem. Our copy/pasted code wasn’t handling token and destination parameters, causing failure at above function. So I reopen sites/default/settings.php file. and edit the rewrite handling code as follow.
SOLUTION:
if (strpos($_SERVER['SERVER_SOFTWARE'], 'LightTPD') !== false) { $_lighty_url = $base_url.$_SERVER['REQUEST_URI']; $_lighty_url = @parse_url($_lighty_url); if ($_lighty_url['path'] != '/index.php' && $_lighty_url['path'] != '/') { $_SERVER['QUERY_STRING'] = $_lighty_url['path']; parse_str($_lighty_url['path'], $_lighty_query); foreach ($_lighty_query as $key => $val) $_GET[$key] = $_REQUEST[$key] = $val; // Note: Lighttpd won't send the querystring attached with clean url if(isset($_lighty_url['query']) && $_lighty_url['query'] != ""){ parse_str($_lighty_url['query'],$myGET); foreach($myGET as $k=>$v) { $_GET[$k] = $v; } } $_GET['q'] = $_REQUEST['q'] = substr($_lighty_url['path'], 1); } }Above final code made my drupal installation on windows running under lighttpd 1.4 for further trouble and solutions… I’ll keep posting.
Recent Comments