[英]Mod-Rewrite: Ignore/exclude parameter when using QSA flag
I'm trying to pass parameters and use the GET
function in PHP on a URL that has already been rewritten using mod rewrite, this is a follow on question from PHP: GET Variables on Mod Rewritten URL . 我正在尝试传递参数,并在PHP上已使用mod rewrite重写的URL上使用
GET
函数,这是PHP提出的以下问题:Mod Rewrite URL上的GET变量 。
This is what I have at present: 这是我目前所拥有的:
RewriteRule ^search/$ ?action=search [L,QSA]
I would like the URL to only show as search/?q=test&p=1
instead of search/?action=search&q=test&p=1
which is what the above rewrite rule gives me, is there a way to tell it to ignore the first parameter on the rule or to ignore a specific parameter? 我希望该URL仅显示为
search/?q=test&p=1
而不是search/?action=search&q=test&p=1
,这是上面的重写规则所提供的,有没有办法告诉它忽略第一个规则中的参数还是忽略特定参数?
RewriteRule ^search/?q=([^/]+)&p=([0-9])$ ?action=search&q=$1&p=$2 [L,QSA]
You can use the following rule with %{THE_REQUEST} variable to match against the full request line: 您可以将以下规则与%{THE_REQUEST}变量一起使用,以与完整的请求行匹配:
RewriteCond %{THE_REQUEST} /search/\?action=[^&]+q=([^&]+)&p=([^&\s]+)$ [NC]
RewriteRule ^ /search/?q=%1&p=%2 [NC,L,R]
This will redirect 这将重定向
to 至
And the following rule will then rewrite : 然后以下规则将被重写:
to its orignal location 到原始位置
?action=foo&q=bar&p=1 ?action = foo&q = bar&p = 1
RewriteRule ^search/$ ?action=search [L,QSA] RewriteRule ^ search / $?action = search [L,QSA]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.