Forum Moderators: phranque

Message Too Old, No Replies

www.example.com/index.php to www.example.com

         

macavity

5:29 pm on Sep 20, 2005 (gmt 0)

10+ Year Member



Hi everyone,

Some time ago this forum's members were kind enough to help me figure out how to rewrite example.com to www.example.com. I ended up with the following code which works perfectly:

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

Over the past few months I've occasionally tried to address my other remaining issue which is to rewrite www.example.com/index.php to www.example.com but I'm going to have to admit defeat, no matter what I try nothing seems to work. What I have at the moment is the following:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule /index\.php$ http://www.example.com/$1 [R=301,L]

Does anyone see anything immediately which I'm doing wrong?

Many thanks in advance for any advice.

Kind regards,

Mac

jd01

5:57 pm on Sep 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, you are VERY close...

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule /index\.php$ http://www.example.com/$1 [R=301,L]

This should be the working version:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]

Simple little adjustments:
No preceding / in the .htaccess on the left side.
No need for the back-reference $1 on the right side.

Hope this helps.

Justin

macavity

6:45 pm on Sep 20, 2005 (gmt 0)

10+ Year Member



OH MY GOD...IT WORKS! Thank you SO MUCH! I can't tell you how many hours I've spent trying to fix it...

Many, many thanks!

Mac