我的 htaccess 中有以下重定向:
重定向 301“^/city/(.*)-north-carolina$”“https://example.com/US/NC/$1-north-carolina-hotels.php”
当我输入 example.com/city/asheville-north-carolina 时,我没有得到应有的重定向。我的语法有问题或者 RewriteCond 需要发生什么事情吗?
我尝试了各种版本的语法,没有任何结果
Redirect
指令仅接受静态 URL 作为输入。
要解决此问题,可以:
将
Redirect
替换为 RedirectMatch
:
RedirectMatch 301 ^/city/(.*)-north-carolina$ https://example.com/US/NC/$1-north-carolina-hotels.php
在这里,
RedirectMatch
将收到 URL 的前导斜杠。
或者
RewriteRule
:
RewriteEngine On
RewriteBase /
RewriteRule ^city/(.*)-north-carolina$ https://example.com/US/NC/$1-north-carolina-hotels.php [R=301,L]
在这种情况下,
RewriteRule
接收不带前导斜杠的路径。