Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to 301 redirect all pages to the same pages on new domain

I'm moving my site from old-domain.com to new-domain.com with exactly the same pages, e.g., if old-domain.com has a page1.html (i.e., old-domain.com/page1.html) then the new domain has the same page, i.e., new-domain.com/page1.html

I tried this in the .htaccess file:

RewriteEngine on
RewriteRule (.*) http://new-domain.com/$1 [R=301,L] 

But only while old-domain.com will redirect to new-domain.com, old-domain.com/page1.html will not redirect to new-domain.com/page1.html

Thanks!

like image 873
Christopher Skyi Avatar asked May 17 '12 20:05

Christopher Skyi


People also ask

When would you 301 redirect every page on a site?

A 301 is used when a page has permanently changed location, and a 302 should be used if you intend to move the page back under the original URL in the future. In general, you should expect to use 301 redirects on your website.

Can you 301 redirect to another domain?

A 301 redirect is a permanent redirect from one URL to another. While they can redirect site page URLs, they can also redirect from one domain to another.


2 Answers

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]

See here for more solutions: http://enarion.net/web/htaccess/migrate-domains/

like image 169
allaire Avatar answered Oct 10 '22 22:10

allaire


Try this in your htaccess

Redirect 301 / http://www.new.com/

This will redirect (and map) all your pages from http://old.com/page1 to http://new.com/page1

like image 29
Janze Siaro Avatar answered Oct 10 '22 22:10

Janze Siaro