提问人:AngryMob 提问时间:10/6/2023 更新时间:10/6/2023 访问量:20
我的带有正则表达式的 htaccess 重定向不起作用
My htaccess redirects with regex aren't working
问:
我的htaccess中有以下重定向:
重定向 301 “^/city/(.*)-north-carolina$” “https://example.com/US/NC/$1-north-carolina-hotels.php”
当我输入 example.com/city/asheville-north-carolina 时,我没有像我应该的那样得到重定向。我的语法有问题,或者 RewriteCond 需要发生什么?
我尝试了各种版本的语法,什么都没有
答:
1赞
Patrick Janser
10/6/2023
#1
该指令仅将静态 URL 作为输入。Redirect
要解决它,请:
替换为
RedirectMatch
:Redirect
RedirectMatch 301 ^/city/(.*)-north-carolina$ https://example.com/US/NC/$1-north-carolina-hotels.php
在这里,将收到 URL 的前导斜杠。
RedirectMatch
或
使用
RewriteRule
:RewriteEngine On RewriteBase / RewriteRule ^city/(.*)-north-carolina$ https://example.com/US/NC/$1-north-carolina-hotels.php [R=301,L]
在本例中,接收不带前导斜杠的路径。
RewriteRule
评论