Redirect all urls, just change the domain name

I have a website with approximately 1,000 URLs. The website is switching to a different domain name. The urls will be exact though, otherwise. I would like to enable htaccess or some rule that redirects 301 for all URLs in one fell swoop. This would substantially replace the domain name as a 301 redirect.

Example: Current URL: domain.com/blog/post-1.html Redirecting to: newdomain.com/blog/post-1.html

And this is done as a 301 redirect. How do I do this? Thanks,

+9
redirect apache .htaccess mod-rewrite
source share
4 answers

Put this rule in your DOCUMENT_ROOT/.htaccess file domain.com :

 RewriteEngine On RewriteCond %{HTTP_HOST} ^(?:www\.)domain\.com$ [NC] RewriteRule ^ http://newdomain.com%{REQUEST_URI} [L,R=301] 
+19
source share

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 on the old site are redirected, and search engines such as Google, Bing, etc., Know that the domain has been constantly moved. This gives the advantage that any rating from domain.com is transferred to newdomain.com. Do not include / after the domain in the rewrite rule, otherwise it will double.

This is an alternative to the method shown above.

+5
source share

With or without www

 RewriteEngine On RewriteCond %{HTTP_HOST} (w*)domain\.com$ [NC] RewriteRule ^ http://newdomain.com%{REQUEST_URI} [L,R=301] 
0
source share

Thanks for answering this question - I had the same question.

Assuming this applies to subdomains as well? so subdomain.newdomain.com?

0
source share

All Articles