Redirecting index.html

Discuss practical ways rearrange URLs using mod_rewrite.

Redirecting index.html

Postby slobjones » Wed May 07, 2008 11:32 am

Although I've long since changed my url and switched to a database system, Google is still showing oldsite.com/index.html in search results.

A standard 301 redirect for index.html prevents my site from loading.

How do I safely redirect calls to index.html to newsite.com?

Here are the redirects I'm currently using:
Code: Select all
RewriteCond %{http_host} ^(www\.)?oldsite.com
RewriteRule ^(.*)$ http://www.newsite.com/$1 [R=301,L]

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

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^index.php/index.php/?(.*)$ http://www.newsite.com/$1 [R=301,L]
slobjones
 
Posts: 32
Joined: Sat Dec 29, 2007 2:56 pm

Postby richardk » Wed May 07, 2008 2:54 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{THE_REQUEST} \ /index\.html(\?.*)?\  [NC]
RewriteRule ^index\.html$ http://www.newsite.com/ [R=301,L]

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

RewriteCond %{HTTP_HOST} ^((www\.)?oldsite\.com|newsite\.com)$ [NC]
RewriteRule ^(.*)$ http://www.newsite.com/$1 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby slobjones » Thu May 08, 2008 8:33 pm

Thanks for your assistance, richardk.

Is it possible this mod could have created a problem with my subdomain?

The sub's address follows the format http://subdomain.oldsite.com

The mod solved the first problem but I then encountered a 403 error when trying to access the subdomain. I believe the message indicated I did not have permission to access index.php.

I restored the old .htaccess and after some delay, was again able to access the subdomain.
slobjones
 
Posts: 32
Joined: Sat Dec 29, 2007 2:56 pm

Postby richardk » Sun May 11, 2008 1:20 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?(oldsite\.com|newsite\.com)$ [NC]
RewriteCond %{THE_REQUEST} \ /index\.html(\?.*)?\  [NC]
RewriteRule ^index\.html$ http://www.newsite.com/ [R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)?(oldsite\.com|newsite\.com)$ [NC]
RewriteRule ^index.php/index.php(/(.*))?$ http://www.newsite.com/$2 [R=301,L]

RewriteCond %{HTTP_HOST} ^((www\.)?oldsite\.com|newsite\.com)$ [NC]
RewriteRule ^(.*)$ http://www.newsite.com/$1 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby slobjones » Mon May 12, 2008 11:52 am

It works!

Many thanks as always for your assistance, richardk.
slobjones
 
Posts: 32
Joined: Sat Dec 29, 2007 2:56 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 58 guests

cron