Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 如何将(301)具有相同路径的多个URL重定向到htaccess中不同域上的_Apache_.htaccess_Redirect_Url Rewriting_Url Redirection - Fatal编程技术网

Apache 如何将(301)具有相同路径的多个URL重定向到htaccess中不同域上的

Apache 如何将(301)具有相同路径的多个URL重定向到htaccess中不同域上的,apache,.htaccess,redirect,url-rewriting,url-redirection,Apache,.htaccess,Redirect,Url Rewriting,Url Redirection,我最近将一个域移动到了一个新的服务器,并在这个过程中更改了一些URL。旧情况: www.domain1.com/page-xyz.html 在新服务器上,可以在以下位置看到相同的页面: www.domain1.com/page-xyz/ www.domain2.com/page-xyz/ 为了确保旧url重定向到新url,我在.htaccess文件中添加了以下行: Redirect 301 /page-xyz.html http://www.domain1.com/page-xyz/ 到

我最近将一个域移动到了一个新的服务器,并在这个过程中更改了一些URL。旧情况:

www.domain1.com/page-xyz.html
在新服务器上,可以在以下位置看到相同的页面:

www.domain1.com/page-xyz/
www.domain2.com/page-xyz/
为了确保旧url重定向到新url,我在.htaccess文件中添加了以下行:

Redirect 301 /page-xyz.html http://www.domain1.com/page-xyz/
到目前为止,一切正常。 现在,我已将第二个域(domain2.com)移动到新服务器。domain1.com和domain2.com都共享同一个目录

在domain2.com的旧服务器上也有这样一个url:

www.domain2.com/page-xyz.html
在新服务器上,可在以下位置查看此页面:

www.domain1.com/page-xyz/
www.domain2.com/page-xyz/
对于这个url,我还想添加一个301重定向。问题是,使用重定向规则后,url
www.domain2.com/page xyz.html
将被重定向到
http://www.domain1.com/page-xyz/
我怎样才能创建一个重定向规则,用它来保存域


非常感谢。

未经测试,但我认为这将使您走上正确的道路:

RewriteCond %{HTTP_HOST} ^domain1.com$
Redirect 301 page-xyz.html http://www.domain1.com/page-xyz/

RewriteCond %{HTTP_HOST} ^domain2.com$
Redirect 301 page-xyz.html http://www.domain2.com/page-xyz/

未测试,但我认为这将使您走上正确的道路:

RewriteCond %{HTTP_HOST} ^domain1.com$
Redirect 301 page-xyz.html http://www.domain1.com/page-xyz/

RewriteCond %{HTTP_HOST} ^domain2.com$
Redirect 301 page-xyz.html http://www.domain2.com/page-xyz/

只需从目标URL中删除域部分:

Redirect 301 /page-xyz.html /page-xyz/

请确保在清除浏览器缓存后对其进行测试。

只需从目标URL中删除域部分:

Redirect 301 /page-xyz.html /page-xyz/
请确保在清除浏览器缓存后对其进行测试