[documentation] [Documentation task] Impossible to use Windows IIS/ISAPI Rewrite with new Clean URL check

hass drupal-docs at drupal.org
Mon Feb 26 14:11:50 UTC 2007


Issue status update for 
http://drupal.org/node/61367
Post a follow up: 
http://drupal.org/project/comments/add/61367

 Project:      Documentation
 Version:      <none>
 Component:    Admin Guide
 Category:     tasks
 Priority:     normal
 Assigned to:  RobRoy
 Reported by:  brashquido
 Updated by:   hass
 Status:       active

the rules need to be extended for Drupal 5:


# Make URLs sane
RewriteRule /install\.php $0 [I,L]


if not, Drupal 5 install isn't working... now we should really happen
all bugs in this rules finally fixed... :-(




hass



Previous comments:
------------------------------------------------------------------------

Tue, 02 May 2006 05:59:20 +0000 : brashquido

Attachment: http://drupal.org/files/issues/system.module (57.38 KB)

With the final release of Drupal 4.7 there seems to be some new code
added (was not present in any RC) which tries to test for Clean URL
compatibility which causes some issues when using ISAPI Rewrite on IIS
with Drupal. The ISAPI rules I use work fine with Drupal once I bypass
this test, the problem is that the method used to test for clean URL's
is dependent on .htaccess.


*Problem No.1*


This new code present on lines 291~300 (inclusive) in system.module
tests for clean URL's, but this code is what generates the test URL;
'<a href ="'. str_replace('?q=', '', url('admin/settings', '',
'clean_url')) .'">'. t('Run Clean URL Test') .'</a>'


Problem with this code is that ISAPI Rewrite does not have the ability
to check for file existance like .htaccess does. This means that when
using the .htaccess the index.php portion of the string is removed, but
not when using ISAPI rewrite. The results of which means you'll get a
URI stem like this when using IIS with ISAPI Rewrite;
/drupal/index.phpadmin/settings&
And this when using Apache with the Drupal .htaccess rules;
/drupal/admin/settings&
Obviously the IIS one is not going to work.


*Problem No.2*


The fact that Drupal tests specfically for a .htaccess based rule isn't
so much a problem, as it has always been this way. The difference is
that you used to be able to execute this SQL directly against your
Drupal database using PHPMyAdmin (or similar) to effectively bypass that
test;
SELECT * FROM variable v WHERE v.name = 'clean_url';
UPDATE variable SET value = 's:1:"1";' WHERE name = 'clean_url';
However, now you are unable to enable Clean URL's in Drupal even if you
manually set it to be enabled directly in the database as system.module
now overides that setting if the Clean URL test fails (which it always
will with ISAPI Rewrite on IIS).


*Solution*


I'll try and take a closer look in the next few days to write a
specific rule for ISAPI Rewrite for this new test, but currently the
only solution for those using Clean URL's with IIS and ISAPI Rewrite is
to manually remove/comment out lines 291~300 (inclusive) in
system.module (or download attached modified version) which effectively
removes Clean URL testing. This will revert the Clean URL setting to the
same way it was in all the RC versions, so be sure that your ISAPI
Rewrite rules are setup or your site will be cactus.


To make things more straight forward for us IIS users, would it please
be possible to place this Clean URL test in an if statement that checks
the _SERVER["SERVER_SOFTWARE"] PHP variable for the existance of Apache
before being executed? That way the test still works for Apache users,
but us IIS users don't have to go digging through code and stripping out
bits just to get Clean URL's to work.




------------------------------------------------------------------------

Tue, 02 May 2006 08:08:38 +0000 : chx

Sorry for the last minute change. As a quickfix put $conf['clean_url'] =
1 to the end of your settings.php.




------------------------------------------------------------------------

Tue, 02 May 2006 12:18:12 +0000 : brashquido

Hi Károly,


I tried putting $conf['clean_url'] = 1 at the very end of my
settings.php file, but it resulted in getting a blank page. I'll do a
search around and see what I can find.




------------------------------------------------------------------------

Tue, 02 May 2006 16:58:43 +0000 : sepeck

I am using clean URL's on IIS with with this line
$conf['clean_url'] = 1; // 1 enables, 0 clears clean_url
on my IIS site.  Now I broke my ISAPI_Rewrite settings so paging
doesn't work but I think that's my fault.


www.blkmtn.org




------------------------------------------------------------------------

Wed, 03 May 2006 01:19:40 +0000 : brashquido

Sorry, my mistake; 


$conf['clean_url'] = 1 is a lot different to $conf['clean_url'] =
1<strong>;</strong>.


Cheers




------------------------------------------------------------------------

Fri, 15 Sep 2006 16:13:32 +0000 : magico

Clean URL test has a few problems in certain conditions that can only be
surpased by admin knowledge and setting a settings.php variable.


In this case, is a "by design" problem.




------------------------------------------------------------------------

Sat, 20 Jan 2007 20:28:26 +0000 : MikeOConnor

I got the whole clean_URLs shebang working a couple minutes ago; Drupal
5, IIS v6.  Here's the cookbook;


- Step 1 -- get ISAPI_Rewrite going (i'm using the paid version so i
can set the rules in the root directory of the virtual web site rather
than for the whole machine)


- Step 2 -- put an httpd.ini file for ISAP_Rewrite in the root
directory of the site, include the following rules in the file;


# Accept a url with the following extensions and pass them through
unchanged.
RewriteRule (.*.gif|.*.png|.*.jpg|.*.pdf|.*.js|.*.css) $1 [I,L]


# Make URLs sane
RewriteRule /index.php.* $0 [I,L]
RewriteRule /(.*)\?(.*) /index.php\?q=$1&$2 [I,L]
RewriteRule /(.*) /index.php\?q=$1 [I,L]


- Step 3 -- add the following line to the settings.php file for the
site (I put it at the end)


$conf['clean_url'] = 1; 


- Step 4 -- modify the database to toggle on the clean-url variable in
the VARIABLE table (note; this is one of the "I'm not sure I really
needed to do this" steps).  I did this with the MySQL Control Center. 
Double-clicked the VARIABLE table to open it, scrolled to the bottom of
the table, selected "insert record" from the Query menu and then;


set the "name" field to --->>>  clean_url
set it's value to --->>>   s:1:"1";


- Step 5 -- modify the system.module file to spoof it into *NOT*
testing to see if if clean_urls will work (that's what this thread is
all about).  Since the shift to Drupal 5 munged up the line numbers for
me, the way I did it was to set the default value of the "test to see if
clean_urls will work" variable to "everything's ok" instead of "nope,
it's not" which then made the program skip the test.  Do a search in the
file to find the old code;


    '#default_value' => variable_get('clean_url', 0),


Replace it with;


    '#default_value' => variable_get('clean_url', 1),  


Note the "0" changing to "1" at the end, that's what spoofs the test.


Step 6 -- start refreshing a few pages on your site, or travelling to
new ones, and see how it's going.  I fooled myself by going to cached
pages a few times.  So go to a page you haven't been to, or refresh the
page.  Clean URLs abound, I hope.  They do for me.  I'm a happy camper.


I'm not sure you absolutely have to do everything I did -- but that
gaggle of steps is what made it work for me.  Clearly, this isn't for
the faint of heart so I wouldn't do this unless you're pretty confident.
 The nice thing is that all of these steps are reversable.  :-)




------------------------------------------------------------------------

Sun, 21 Jan 2007 13:30:06 +0000 : rubensans

Thanks you MikeOConnor for your contribution  !!!


I have been testing a lot and you only need to do:


1.- Put in HELICON ISAPI REWRITE this:


# Accept a url with the following extensions and pass them through
unchanged.
RewriteRule (.*.gif|.*.png|.*.jpg|.*.pdf|.*.js|.*.css) $1 [I,L]


# Make URLs sane
RewriteRule /index.php.* $0 [I,L]
RewriteRule /(.*)\?(.*) /index.php\?q=$1&$2 [I,L]
RewriteRule /(.*) /index.php\?q=$1 [I,L]


2.-  Add the following line to the settings.php file for the site (I
put it at the end)


$conf['clean_url'] = 1; 


Best Regards.




------------------------------------------------------------------------

Tue, 23 Jan 2007 18:40:58 +0000 : hass

Someone able to update the wrong / incomplete Handbook under
http://drupal.org/node/46429 please?




------------------------------------------------------------------------

Tue, 23 Jan 2007 19:19:30 +0000 : RobRoy

Fixed that handbook page. Look okay?




------------------------------------------------------------------------

Sat, 27 Jan 2007 09:12:18 +0000 : hass

thank you for the handbook update... Asside this ISAPI rules are buggy


i got page not found errors since i use them:
http://localhost/drupal/index.php?q=cron.php




------------------------------------------------------------------------

Sat, 27 Jan 2007 09:13:37 +0000 : hass

other URLs maybe broken, too.


update.php
xmlrpc.php




------------------------------------------------------------------------

Tue, 30 Jan 2007 17:39:14 +0000 : brashquido

Hi All,


I wrote an article on my website about this;


http://www.iis-aid.com/articles/how_to_guides/using_drupal_clean_urls_wi...


About the the only thing these ISAPI Rewrite rules don't do is enable
the clean url radio button. Still working on that.




------------------------------------------------------------------------

Tue, 30 Jan 2007 19:09:58 +0000 : RobRoy

If we get some feedback saying that those rewrite rules work, I'll
incorporate them into the handbook page. I don't have IIS to test, so
I'm just going off public feedback.




------------------------------------------------------------------------

Tue, 30 Jan 2007 22:35:37 +0000 : hass

@brashquido: Your variant isn't working at all. Aside if you document
something that should be cut and paste then please use PRE.


Error: Bad regular expression at lines 4 - 4.


# Accept a url with the following directories and pass them through
unchanged. 
RewriteRule /(?:misc|files|modules|themes|sites|uploads|)/(.*) $0 [I,L]


# Make URLs sane 
RewriteRule /cron\.php $0 [I,L] 
RewriteRule /index\.php.* $0 [I,L] 
RewriteRule /update\.php.* $0 [I,L] 
RewriteRule /robots\.txt $0 [I,L] 
RewriteRule /xmlrpc\.php $0 [I,L] 
RewriteRule /(.*)\?(.*) /index.php\?q=$1&$2 [I,L] 
RewriteRule /(.*?)(?:/page_(\d+))? /index.php\?q=$1?2&page=$2: [I,L] 
RewriteRule /(.*) /index.php\?q=$1 [I,L]




------------------------------------------------------------------------

Wed, 31 Jan 2007 01:20:41 +0000 : brashquido

Thanks for the catch on the formatting issue Hass. Those rules are
working for me though, they are a direct copy & paste from my production
server. Not sure why you are getting a Bad regular expression error,
I'll take a look at it.




------------------------------------------------------------------------

Wed, 31 Jan 2007 18:23:57 +0000 : hass

@brashquido: the bug seems the pipe after uploads.


*ISAPI Rewrite config if Drupal is installed in a subdirectory*
(Solution requires ISAPI_Rewrite >=2.9 Build 63)
[ISAPI_Rewrite]

# You must change/remove prefixes if Drupal is not installed in a
subdirectory
# Specify namespaces with UriMatchPrefix - DO NOT CHANGE ORDER
UriMatchPrefix /drupal

# Accept a url with the following directories and pass them through
unchanged. 
RewriteRule /(?:misc|files|modules|themes|sites|uploads)/(.*) $0 [I,L]

# Make URLs sane 
RewriteRule /cron\.php $0 [I,L]
RewriteRule /index\.php.* $0 [I,L]
RewriteRule /update\.php.* $0 [I,L]
RewriteRule /xmlrpc\.php $0 [I,L]

# deactivate following line if "robotstxt" module is installed
#RewriteRule /robots\.txt.* $0 [I,L]

# specify namespaces with UriFormatPrefix - DO NOT CHANGE SUXXX ORDER
UriFormatPrefix /drupal

RewriteRule /(.*)\?(.*) /index.php\?q=$1&$2 [I,L]
RewriteRule /(.*?)(?:/page_(\d+))? /index.php\?q=$1?2&page=$2: [I,L]
RewriteRule /(.*) /index.php\?q=$1 [I,L]

# reset namespaces to default
UriMatchPrefix
UriFormatPrefix


*ISAPI Rewrite config if Drupal is installed in Webservers Root*
[ISAPI_Rewrite]

# Accept a url with the following directories and pass them through
unchanged. 
RewriteRule /(?:misc|files|modules|themes|sites|uploads)/(.*) $0 [I,L]

# Make URLs sane 
RewriteRule /cron\.php $0 [I,L]
RewriteRule /index\.php.* $0 [I,L]
RewriteRule /update\.php.* $0 [I,L]
RewriteRule /xmlrpc\.php $0 [I,L]

# deactivate following line if "robotstxt" module is installed
#RewriteRule /robots\.txt.* $0 [I,L]

RewriteRule /(.*)\?(.*) /index.php\?q=$1&$2 [I,L]
RewriteRule /(.*?)(?:/page_(\d+))? /index.php\?q=$1?2&page=$2: [I,L]
RewriteRule /(.*) /index.php\?q=$1 [I,L]




------------------------------------------------------------------------

Wed, 31 Jan 2007 22:43:41 +0000 : brashquido

*slapshead* Of course it is. I didn't get any time really to look at it
yesterday, but after copying and pasting my rules into my article I
removed an entry for the AWStats "js" directory after uploads. I
obviously neglected to remove associate pipe symbol. 


While we are at it the second last rule should be removed or
deactivated. This was an attempt to get fully Clean URL's when using the
paging module (sample_article/page1 instead of sample_article/?page=0,1)
but I never got around to finishing it as I read that using the paging
module can lead to search engine penalization as they see the pages as
duplicate data. Thanks for the help there Hass, I think the rules should
be pretty clean now. The only thing I haven't been able to resolve or
had a lot of time to look into is the "Clean URL Test" in the Drupal
admin. 


[ISAPI_Rewrite]

# Accept a url with the following directories and pass them through
unchanged.
RewriteRule /(?:misc|files|modules|themes|sites|uploads)/(.*) $0 [I,L]

# Make URLs sane
RewriteRule /cron\.php $0 [I,L]
RewriteRule /index\.php.* $0 [I,L]
RewriteRule /update\.php.* $0 [I,L]
RewriteRule /xmlrpc\.php $0 [I,L]

# deactivate following line if "robotstxt" module is installed
#RewriteRule /robots\.txt.* $0 [I,L]

RewriteRule /(.*)\?(.*) /index.php\?q=$1&$2 [I,L]
RewriteRule /(.*) /index.php\?q=$1 [I,L]




------------------------------------------------------------------------

Fri, 02 Feb 2007 20:50:43 +0000 : RobRoy

If we get confirmation on an exact ruleset, I'll put it in that handbook
page. @hass can you confirm that works? Anyone else on IIS?




------------------------------------------------------------------------

Sat, 03 Feb 2007 09:18:18 +0000 : hass

yes, the last and the two versions i posted are working, but as
brashquido said the RewriteRule /(.*?)(?:/page_(\d+))?
/index.php\?q=$1?2&page=$2: [I,L] should be removed from my versions.
please document the "drupal in subdirectory" version as well. maybe
without the "suxxx" comment :-).




------------------------------------------------------------------------

Sun, 04 Feb 2007 02:35:26 +0000 : ckjian

I'm using IIS too. The rules provided work for me as well. But has
anyone test this with banner.module as well? I've tried adding two rules
identical to cron.php for the two banner files which are placed on the
root.


RewriteRule /banner_db\.php $0 [I,L]
RewriteRule /banner_file\.php $0 [I,L]


but at the log message, it stated that the banner_db.php is not found.




------------------------------------------------------------------------

Sun, 04 Feb 2007 09:05:12 +0000 : hass

The bad side of the Helicon ISAPI_Rewrite is, this config needs to be
extended by every filename that is located in the webroot...  maybe you
have a problem with the CacheClockRate 3600 that isn't available in the
lite version if i remember correctly. i tried your rule in the regex
tester and it works. i don't know why it shouldn't work.


Aside, why are this banner files located in the webroot? i thought this
is only a core file location... shouldn't this files in the
modules/banner directory? i never used / tryed this banner module...






More information about the documentation mailing list