htaccess将所有页面重写到另一个域的同一页面

时间:2021-09-08 15:20:16

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.

所以我一直在寻找,但到目前为止都无法找到我正在寻找的东西。看看这篇文章如何使用.htaccess将所有页面转发到不同域上的同一页面?但它似乎只重定向我的主页。

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.

目前,我正在使用WordPress,我需要能够将所有页面转发到新域。例如,domain1.com/about-us需要转到domain2.com/about-us。但我需要处理大约50页。我想看看是否有1-5行代码用于此工作。

Thanks!

谢谢!

1 个解决方案

#1


12  

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

尝试将此(在任何wordpress规则之上)放在domain1.com的文档根目录中的htaccess文件中:

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:

如果您的2个域是一个不同的Web服务器,或者不共享公共文档根,则可以使用mod_alias,将其添加到domain1.com的文档根目录中的htaccess文件中:

Redirect 301 / http://domain2.com/

#1


12  

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

尝试将此(在任何wordpress规则之上)放在domain1.com的文档根目录中的htaccess文件中:

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:

如果您的2个域是一个不同的Web服务器,或者不共享公共文档根,则可以使用mod_alias,将其添加到domain1.com的文档根目录中的htaccess文件中:

Redirect 301 / http://domain2.com/