I have moved my old site to new domain but google is still showing my previous links so i made a htaccess file and made 301 redirect. Below is my htaccess code :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.old.com$
RewriteRule (.*)$ http://new.com/$1 [R=301,L]
It is redirecting old url to new url but it is not doing it page by page. Means if i am going to www.old.com/about.php then it is redirecting me to www.new.com/ but i want www.new.com/about.php to appear.
can u suggest me how to do this with the use of proper regular expression with minimal work ?
This would maintain everything - the query string and the request path:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.old.com$
RewriteRule ^(.*)$ http://new.com/$1 [R=301,L,QSA]
You don't need to use mod_rewrite at all. Simply use:
<VirtualHost *:80>
ServerName old.com
ServerAlias www.old.com
Redirect permanent / http://new.com/
</VirtualHost>
The Redirect
directive automatically preserves anything after the /
.