Forum Moderators: phranque

Message Too Old, No Replies

301 Redirect Question - Home Page

         

jpservicez1

8:52 pm on Aug 20, 2008 (gmt 0)

10+ Year Member



I need small help to post a 301 redirect code in my .htaccess.

I currently have this code in my .htaccess

RewriteCond %{THE_REQUEST} /index\.php\ HTTP/
RewriteRule ^index\.php$ / [R=301,L]

This redirects my "/index.php" to " / "

http://www.example.com/index.php "TO"
http://www.example.com/

But I also want to redirect "/index.php/" to " / "

http://www.example.com/index.php/
http://www.example.com/

Please advise

jdMorgan

9:38 pm on Aug 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Any character in a regex pattern can be made optional by following it with a "?"

Please see the resources cited in our forum charter.

Jim

ag_47

9:40 pm on Aug 20, 2008 (gmt 0)

10+ Year Member



RewriteCond %{THE_REQUEST} /index\.php\ HTTP/
RewriteRule ^index\.php/?$ [R=301,L]

=> Add /? to test for the trailing slash.

jpservicez1

10:10 pm on Aug 20, 2008 (gmt 0)

10+ Year Member



Hmmm.. not working

The link with "/index.php/" is not redirecting to " / " with the above code..

Am missing something here..the question is what is it?

jdMorgan

10:14 pm on Aug 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The proposed 'fix' is only half-done.

Jim

ag_47

10:23 pm on Aug 20, 2008 (gmt 0)

10+ Year Member



oops, missing the redirect path.

RewriteCond %{THE_REQUEST} /index\.php/?\ HTTP/ [NC]
RewriteRule ^index\.php/?$ / [R=301,L]

And I think you don't have to check for index.php in the RewriteCond, this is already met by the rule. Just a check for HTTP is enough..?

jpservicez1

10:28 pm on Aug 20, 2008 (gmt 0)

10+ Year Member



Thanks guys it works now..