Forum Moderators: phranque

Message Too Old, No Replies

Mod_rewrite Question

Help with mod_rewrite

         

dizzynutter

11:07 am on Aug 8, 2005 (gmt 0)

10+ Year Member



RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ [mydomain.com...] [R=301,L]

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^mydomain\.com
RewriteRule (.*) [mydomain.com...] [R=301,L]

I have the above rules in my .htaccess file, but I have the following problems.

[mydomain.com...] produces a 404 error, would like to produce [mydomain.com...]

AND

[mydomain.com...] produces a 300 error, would like to produce [mydomain.com...]

Any help would be much appreciated
Thanks,
Dizzynutter

jd01

5:36 pm on Aug 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi dizzynutter,

Welcome to WebmasterWorld.

There are a couple of ways to do this:

Using the implicit 'and anything else' is the fastest, but has the lease control:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index [NC]
RewriteRule ^index http://mydomain.com/ [NC,R=301,L]

Using the 0 or 1 (?) flag will also work:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index(\.html)?/?\ HTTP/ [NC]
RewriteRule ^index(\.html)?/?$ http://mydomain.com/ [NC,R=301,L]

Adding the 'No Cose' (NC) flag will make INDEX a match.

Use the one you think works best for you.

Hope this helps.

Justin

dizzynutter

9:00 pm on Aug 8, 2005 (gmt 0)

10+ Year Member



Hi Justin,

Both rules work fine, I will use the 2nd rule as this seems to be faster.

Thanks for your help.
Dizzynutter