我希望将不以尾随斜杠结尾的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实现这一点?
发布于 2014-10-27 08:01:13
您的RewriteCond有错误的正则表达式模式,请使用以下规则:
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} ^/[^.]+$
RewriteCond %{HTTP_HOST} =origin.example.com
RewriteRule [^/]$ http://example.com%{REQUEST_URI}/ [R=301,L]
</IfModule>https://stackoverflow.com/questions/26583076
复制相似问题