Forum Moderators: phranque

Message Too Old, No Replies

Removing site.com/index.php from SE

         

reggy

10:40 pm on Jun 7, 2007 (gmt 0)

10+ Year Member



How do i redirect my site.com/index.php to site.com as both results appear in search results and they are duplicates?

jdMorgan

1:04 am on Jun 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you familiar with Apache mod_rewrite? If so, do you currently have any working RewriteRules on your server?

Just trying to establish where we need to start here...

Jim

reggy

1:02 am on Jun 9, 2007 (gmt 0)

10+ Year Member



am not familiar with mod_rewrite but i do have a mod_rewrite in my .htaccess file

jdMorgan

1:09 am on Jun 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Good, if you already have a working rule that means you can start with these threads [google.com] -- Saves a lot of preliminary testing.

Jim

reggy

1:22 am on Jun 9, 2007 (gmt 0)

10+ Year Member



JDMorgan,
I tried a few things but didnt seem to work - this is what ive got in my .htacess

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

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

Options +FollowSymLinks
RewriteEngine on
rewritecond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
rewriterule ^index\.php$ http://www.example.com/ [R=301,L]

Thanks

[edited by: jdMorgan at 1:36 am (utc) on June 9, 2007]
[edit reason] Example.com [/edit]

jdMorgan

1:40 am on Jun 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You've got some problems with the order of the rules, and with redundant directives. Try this:

<IfModule mod_rewrite.c>
#
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
#
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
RewriteBase /blog
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
#
</IfModule>

Generally, put external redirects first, most-specific to least-specific, then internal rewrites.

The RewriteBase on the blog rewrite was probably interfering with your other rules

Jim

reggy

2:02 am on Jun 9, 2007 (gmt 0)

10+ Year Member



JDMorgan,
it worked fine - thanks a lot for the prompt help

reggy

11:06 pm on Jun 22, 2007 (gmt 0)

10+ Year Member



jDMorgan - actually i just noticed that it was causing my 404 error page not to work properly - it just kept redirecting to my homepage