.htaccess 301 重定向,保留路径

Posted

技术标签:

【中文标题】.htaccess 301 重定向,保留路径【英文标题】:.htaccess 301 redirect, keeping paths 【发布时间】:2014-06-22 23:46:24 【问题描述】:

我正在尝试将 www.olddomain.com/content/path 重定向到 www.newdomain.com/content/path

不知何故:

.htaccess 301 redirect path and all child-paths

RewriteEngine On
RewriteRule ^(.*)$ http://newdomain.com/ [R=301]

不工作并且总是重定向到索引。

谢谢!

【问题讨论】:

【参考方案1】:

因为您在目标 URL 中缺少捕获的组 $1

RewriteEngine On
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]

或者你可以这样做:

RewriteEngine On
RewriteRule ^ http://newdomain.com%REQUEST_URI [L,R=301]

【讨论】:

【参考方案2】:

阿努巴瓦,

两者有什么区别:

RewriteEngine On
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]

或者你可以这样做:

RewriteEngine On
RewriteRule ^ http://newdomain.com%REQUEST_URI [L,R=301]

【讨论】:

以上是关于.htaccess 301 重定向,保留路径的主要内容,如果未能解决你的问题,请参考以下文章