【问题标题】:Redirect URLs without trailing slash to a different domain with trailing slash in .htaccess将不带斜杠的 URL 重定向到 .htaccess 中带有斜杠的不同域
【发布时间】:2014-12-22 08:48:15
【问题描述】:

我想将不以斜杠结尾的 URL 重定向到在不同域上具有相同路径但以斜杠结尾的 URL。

例如:

 origin.example.com\my-awesome-post  -> example.com\my-awesome-post\  - redirect
 origin.example.com\my-awesome-post\ - shouldn't be redirected

我当前的 .htaccess 配置不起作用:

<IfModule mod_rewrite.c>
 RewriteCond %{REQUEST_URI} /+[^\.]+$
 RewriteCond %{HTTP_HOST} origin.example.com\.com$ [NC]
 RewriteRule ^(.+[^/])$ http://example.com/%{REQUEST_URI}/ [R=301,L]
</IfModule>

有什么建议可以用 .htaccess 实现吗?

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect url-rewriting


    【解决方案1】:

    您的RewriteCond 的正则表达式模式错误,请使用此规则:

    <IfModule mod_rewrite.c>
      RewriteCond %{REQUEST_URI} ^/[^.]+$
      RewriteCond %{HTTP_HOST} =origin.example.com
      RewriteRule [^/]$ http://example.com%{REQUEST_URI}/ [R=301,L]
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多