regex - htaccess重写匹配问号

标签 regex .htaccess mod-rewrite url-rewriting

我需要有关重写规则和正则表达式的帮助

这是我的输入网址

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/

相关文章:

.htaccess - Mediawiki 的缩略图处理程序(重写)不起作用

php - .htaccess 将我的索引更改为相关页面

regex - 不同域图片的 URL 重写

javascript - JSLint 正则表达式违规问题

php - 带有转义圆括号的正则表达式

调车场算法能否解析POSIX正则表达式?

regex - 带空格的 HTML5 表单验证模式字母数字?

wordpress - 如何将特定网址的 https 重写为 http?

java - 如何在集群 apache tomcat 环境中使用 MOD Rewrite 缩短我的 URL

php - Apache 重写 - 本地主机中的干净 URL