htaccess:如何重写特定的 GET 变量?
对于主菜单,我有大约 3 个标题类别 我喜欢静态重写它们。
这是我现在使用的代码:
RewriteCond %{QUERY_STRING} !dep= [NC]
RewriteRule ^([0-9a-zA-Z-]+)/?$ index.php?dep=$1 [NC,L,QSA]
www.hello.com/car/ 将给出 //$_GET var //?dep=car
简单的我将如何让:www.hello.com /汽车/福特/
let 'return' ?dep=car&id=ford
现在假设我知道我正在使用的 3 个 '?dep' 参数。你怎么能写:
If www.hello.com/? == car || boat || train /
rewrite to ?dep=
else
rewrite to ?id=
/*
In this example giving www.hello.com/ford/
would return id=ford
but, www.hello.com/boat/
would return dep=boat
*/
For a main menu I've got about 3 header catagoty's
I like to static rewrite them.
This is the code i'm using now:
RewriteCond %{QUERY_STRING} !dep= [NC]
RewriteRule ^([0-9a-zA-Z-]+)/?$ index.php?dep=$1 [NC,L,QSA]
www.hello.com/car/ will give the //$_GET var //?dep=car
simple how would I let: www.hello.com/car/ford/
let 'return' ?dep=car&id=ford
Now let say I know the 3 '?dep' paramters I'm using. How could you write:
If www.hello.com/? == car || boat || train /
rewrite to ?dep=
else
rewrite to ?id=
/*
In this example giving www.hello.com/ford/
would return id=ford
but, www.hello.com/boat/
would return dep=boat
*/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的规则之后添加此规则:
你需要改变你的条件,因为你需要检查“id”。然后该规则将专门匹配“汽车”、“船”或“火车”:
并为其余规则添加第二条规则:
Add this rule after your rules:
You'll need to change your conditions for this because you need to check for "id". Then the rule would match "car", "boat", or "train" specifically:
And add a second rule for the rest: