Welcome to WebmasterWorld Guest from 174.129.151.95

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Redirect all /index.php urls to /

redirect index.php

   
3:56 am on Aug 24, 2012 (gmt 0)



Hi,

I am trying to redirect all index.php urls site wide to the url without index.php to prevent duplicate content but can only seem to redirect the homepage url and not the internal urls. If someone is able point out where I am going wrong that would be great.

This is what my .htaccess file currently looks like:

Options +FollowSymLinks
DirectoryIndex index.php

RewriteEngine on

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php(/[^\ ]*)?\ HTTP/
RewriteRule ^index\.php(/(.*))?$ http://www.example.com/$2 [R=301,L]

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

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

[edited by: incrediBILL at 9:32 am (utc) on Aug 24, 2012]
[edit reason] unlinked URLs in code [/edit]

4:08 am on Aug 24, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



I have this from this same forum, some time ago:

# redirect all <subdirectory>/index.html requests to <subdirectory>/
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.html[^\ ]*\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://www.example.com/$1? [R=301,L]

I made same question like you, except it was for HTML vs. your PHP which does not really make any difference. The code was written by a guru that mastered this thread in the past (jdMorgan), so I doubt it can get any better.

In your case, I believe it would look like this:

# redirect all <subdirectory>/index.php requests to <subdirectory>/
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.php[^\ ]*\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1? [R=301,L]

Certainly, replace the "example.com" with your URL. Test it. It works with home page and subdirectories as well.

Cheers!
4:57 am on Aug 24, 2012 (gmt 0)



Jackpot! Thanks a lot mate.
6:29 am on Aug 24, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



In the original post, in the target URL in rule 2 you do not need the quotes nor the escaping.
8:49 am on Aug 24, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



RewriteRule ^index\.php(/(.*))?$ http://www.example.com/$2 [R=301,L]

What would you expect to find after "index.php"? (Please don't say "a query string". It's almost 2AM and I can't deal with it.)

This Rule works only on the top-level site index, because you've put your opening anchor right in front of the "index.php" both in the Rule itself and in the Condition. Did your cat walk across the keyboard? Somehow the pattern seems to have got turned backward.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month