Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess rewrite all pages to same page on another domain

So I've been looking but so far can;t find something that I'm looking for exactly. Looked at this article How can I forward ALL pages to the same exact page on a different domain using .htaccess? but it seems to only redirect my home page.

Currently, I'm using WordPress and I need to be able to forward all pages to a new domain. For example, domain1.com/about-us needs to go to domain2.com/about-us. But I have about 50 pages this needs to work on. I would like to see if there is a 1-5 line code to use for this to work.

Thanks!

like image 764
Enrico Avatar asked Aug 14 '12 00:08

Enrico


People also ask

How do I redirect a whole website to another domain?

Under the Domain category, choose the Redirects menu. You'll see the Create a Redirect section. Here, you'll need to fill in which URL you want to Redirect and where you want it to Redirect To. Make sure your information is correct and choose the right connection protocol – HTTP or HTTPS.

What is the difference between 301 and 302 redirect?

While a 301 redirect indicates that a page has permanently moved to a new location, a 302 redirect means that the move is only temporary. Keep reading to learn more. There are two redirects that can be used to direct site users and search engines to a different URL than they'd originally planned to visit.

What is a 301 .htaccess redirect?

A 301 Permanent Redirect permanently redirects one URL to another. You set up a 301 redirect using . htaccess to send visitors to a new URL and tell search engines that a page has moved so that the new page can be properly indexed.

Should I enable 301 .htaccess redirect?

The . Because the WordPress 301 redirect is not always reliable, we recommend issuing the 301 redirect via your . htaccess file. Another benefit is that the . htaccess redirect is slightly faster than redirecting via PHP, because it is loaded even before the rest of the page.


1 Answers

Try putting this (above any wordpress rules) in the htaccess file in domain1.com's document root:

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

If your 2 domains are one different webservers, or don't share a common document root, you can just use mod_alias, adding this to the htaccess file in domain1.com's document root:

Redirect 301 / http://domain2.com/
like image 176
Jon Lin Avatar answered Sep 29 '22 09:09

Jon Lin