RewriteRule Issues

Sep 29, 2009 at 2:45 PM

I am trying to upload an existing site, and looking to convert existing .htaccess files to an ini for IIRF.

It looks like this...

 

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.domainname.com$ [NC]
RewriteRule ^(.*)$ http://www.domainname.com/$1 [R=301,L]

RewriteRule ^(file1|file2|file3)$ /$1.php

This then loads file1.php if this url is entered www.domainname.com/file1

This works on the current server, but on my iis6 server, with php installed, and copying the text above into the ini file, it comes up 404 when i put in the above url.

 

Any ideas where i'm going wrong ?

Sep 29, 2009 at 5:07 PM

You're omitting the leading forward slash.

If you use the following rule:

RewriteRule ^/(file1|file2|file3)$ /$1.php

it should work. Maybe consider checking against a trailing slash too, like:

RewriteRule ^/(file1|file2|file3)/?$ /$1.php

Hope this helps.

Coordinator
Sep 29, 2009 at 8:09 PM

Try this:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?!www\.domainname\.com)$ [NC]
RedirectRule ^(.*)$ http://www.domainname.com/$1 [R=301]

RewriteRule ^/(file1|file2|file3)$ /$1.php

You need the slash, as shonk said. You also need to use RedirectRule instead of RewriteRule, if you want to redirect. And, the negation in the RewriteCond needs to be different.