Apache 用参数重写规则?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1546535/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 18:14:22  来源:igfitidea点击:

Apache rewrite rule with parameters?

apachemod-rewriteurl-rewriting

提问by James

I have the following URL:

我有以下网址:

http://domain.com/index.php?m=feedback&cSubject=My Subject

I want to have a rewrite rule so that the following:

我想有一个重写规则,以便以下内容:

http://domain.com/feedback?Subject=My Subject

maps to the previous url. Heres my rule at the moment:

映射到前一个 url。这是我目前的规则:

RewriteRule ^feedback?Subject=(.*)$ index.php?m=feedback&cSubject=

Doesn't seem to be working tho! Any ideas?

似乎没有工作!有任何想法吗?

回答by clops

Query Strings are not parsed by Apache Mod_Rewrite, but there is a workaround. Try this

Apache Mod_Rewrite 不会解析查询字符串,但有一个解决方法。尝试这个

RewriteRule ^feedback/?$ index.php?m=feedback&c%{QUERY_STRING} [NC,L]

回答by Kepi

You can use RewriteCond statement to do exactly what you want:

你可以使用 RewriteCond 语句来做你想做的事:

RewriteEngine On

RewriteCond %{QUERY_STRING} Subject=(.*)
RewriteRule ^feedback$ index.php?m=feedback&cSubject=%1 [L]

回答by Tim Smith

There seems to be an = missing from clops answer to give..

clops 答案中似乎缺少一个 = 给出..

RewriteRule ^feedback/?$ index.php?m=feedback&c=%{QUERY_STRING} [NC,L]

.. at least I need one to make it work.

.. 至少我需要一个来让它工作。