我需要有关重写规则和正则表达式的帮助
这是我的输入网址
http://localhost/ws/rest/user/login?login=user_login&password=user_pass
我希望它重定向到此
http://localhost/index.php?type=rest&ressource=user&action=login&login=user_login&password=user_pass
我的重写规则
RewriteCond %{REQUEST_METHOD} ^(GET|POST)
RewriteRule ^ws/(.+)/(.+)/([A-Za-z]+)(\\?)(.+)? index.php?type=$1&ressource=$2&action=$3&$5 [L]
我认为问题出在网址中的 ?
上,因为当我替换为 &
时它可以工作吗?
最佳答案
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(GET|POST)
RewriteRule ^ws/([^/]+)/([^/]+)/([A-Za-z]+) index.php?type=$1&resource=$2&action=$3 [QSA,L]
注意QSA
标志,以便将原始 URL 中的查询字符串附加到新 URL。
关于regex - htaccess重写匹配问号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19142202/