.htaccess 301重定向,保持路径

时间:2014-05-06 11:26:20

标签: regex apache .htaccess mod-rewrite redirect

我正在尝试将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]

不工作且始终重定向到索引。

谢谢!

2 个答案:

答案 0 :(得分:8)

因为您在目标网址中缺少已捕获的群组$1

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

或者你可以这样做:

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

答案 1 :(得分:0)

anubhava,

两者之间有什么区别

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

或者您可以这样做:

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