【问题标题】:.htaccess 301 redirect, keeping paths.htaccess 301 重定向,保留路径
【发布时间】: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]

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

谢谢!

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite redirect


    【解决方案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]
      

      【讨论】:

        猜你喜欢
        • 2010-10-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-10
        • 2014-06-23
        • 2017-10-28
        • 2020-10-01
        • 1970-01-01
        相关资源
        最近更新 更多