我正在使用此重写规则来重定向我的搜索请求:RewriteRule ^search/([^/\.]*)/([^/]+)/?$ index.php?search=$1&additional=$2 [L]此规则适用于search/search/add但是它给了我一个页面没有找到search//add(空搜索)我做错了什么?正则表达式应该匹配:
RewriteRule ^search/([^/\.]*)/([^/]+)/?$ index.php?search=$1&additional=$2 [L]
search/search/add
search//add
Debuggex Demo
5cnsuln71#
是的,您的正则表达式将匹配search//add,但问题是mod_rewrite引擎在RewriteRule指令中将多个斜线剥离为一个。您可以改用RewriteCond:
mod_rewrite
RewriteRule
RewriteCond
RewriteCond %{REQUEST_URI} ^/search/([^/.]*)/([^/]+)/?$ [NC] RewriteRule ^ index.php?search=%1&additional=%2 [L,QSA]
1条答案
按热度按时间5cnsuln71#
是的,您的正则表达式将匹配
search//add
,但问题是mod_rewrite
引擎在RewriteRule
指令中将多个斜线剥离为一个。您可以改用
RewriteCond
: