对于没有尾随斜杠的URL,Htaccess重定向失败

时间:2018-02-25 11:12:47

标签: .htaccess url-redirection trailing-slash trailing

我正在努力应对来自两者的htaccess重定向:

/ folder / subfolder / any-value / / folder /子文件夹/任意值 / another-folder / any-value /

以下代码适用于

/ folder /子文件夹/ any-value / / another-folder / any-value /

但不是:

/ folder /子文件夹/任意值 / another-folder / any-value /

RewriteRule ^england/devon-cornwall/(.*)/$ https://www.example.com/large-houses/$1/ [R=301,L]

作为额外的crtiera,网址 / folder / subfolder / 应保持不变。

我已经搜索了高位和低位以修复网址上的尾部斜杠问题,但找不到任何内容。请有人帮忙吗?谢谢!

1 个答案:

答案 0 :(得分:0)

尝试:

RewriteRule ^england/devon-cornwall/(.*)/?$ https://www.example.com/large-houses/$1/ [R=301,L]

/?表示/是可选的,因此它将uri与traling斜杠匹配,uri在末尾没有斜杠。

在测试此

之前清除浏览器缓存