如何摆脱导致连续重定向的错误?我希望这些规则在两个方向上都能发挥作用。
RewriteEngine On
RewriteRule ^search/([a-z0-9-]+)/$ search.php?name=$1
RewriteCond %{QUERY_STRING} ^name=(.*)$
RewriteRule ^search\.php$ https://example.com/search/%1/? [L,R=301]
答案 0 :(得分:0)
存在重定向循环 您可以使用环境变量来检查您的网址是否在重定向上下文中
# redirect pretty url to real php
RewriteRule ^search/([a-z0-9-]+)/$ search.php?name=$1 [L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^name=(.*)$
# force pretty url with 301 unless in a rewrite
RewriteRule ^search\.php$ https://example.com/search/%1/? [L,R=301]