I have a website with roughly 1K URLs. The website is moving to a different domain name. The URLs will be the exact same though, otherwise. I\'d like to incorporate an htacc
Place this rule in your DOCUMENT_ROOT/.htaccess
file of domain.com
:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)domain\.com$ [NC]
RewriteRule ^ http://newdomain.com%{REQUEST_URI} [L,R=301]
When moving a domain name to a new domain where the only change to the url is the domain name, I use the following redirect in my Apache .htaccess file
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^(.*)$ http://newdomain.com$1 [R=301,L]
This ensures that all links in the old site are redirected and search engines like Google, Bing etc. are aware that the domain was permanently moved. This has the benefit that any ranking from domain.com is transferred to newdomain.com. Make sure not to include a /
after the domain in the rewrite rule or it will double-up.
This is an alternative to the method shown above.
With www or without
RewriteEngine On
RewriteCond %{HTTP_HOST} (w*)domain\.com$ [NC]
RewriteRule ^ http://newdomain.com%{REQUEST_URI} [L,R=301]