.htaccess htaccess:如何重写特定的GET变量?
对于主菜单,我有大约3个标题catagoty's 我喜欢静态重写它们 这是我现在使用的代码:.htaccess htaccess:如何重写特定的GET变量?,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,对于主菜单,我有大约3个标题catagoty's 我喜欢静态重写它们 这是我现在使用的代码: RewriteCond %{QUERY_STRING} !dep= [NC] RewriteRule ^([0-9a-zA-Z-]+)/?$ index.php?dep=$1 [NC,L,QSA] www.hello.com/car/将给出/$\u GET var//?dep=car 我该如何让:www.hello.com/car/ford/ 让我们“返回”?dep=汽车和id=福特 现
RewriteCond %{QUERY_STRING} !dep= [NC]
RewriteRule ^([0-9a-zA-Z-]+)/?$ index.php?dep=$1 [NC,L,QSA]
www.hello.com/car/将给出/$\u GET var//?dep=car
我该如何让:www.hello.com/car/ford/让我们“返回”?dep=汽车和id=福特 现在假设我知道我使用的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
*/
简单的我该怎么让:www.hello.com/car/ford/let'return'?dep=car&id=ford
在规则之后添加此规则:
RewriteRule ^([0-9a-zA-Z-]+)/([0-9a-zA-Z-]+)/?$ index.php?dep=$1&id=$2 [NC,L,QSA]
现在假设我知道我使用的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
*/
您需要为此更改条件,因为您需要检查“id”。然后,规则将特别匹配“汽车”、“船”或“火车”:
RewriteCond %{QUERY_STRING} !(id|dep)= [NC]
RewriteRule ^(car|boat|train)/?$ index.php?dep=$1 [NC,L,QSA]
并为其余部分添加第二条规则:
RewriteCond %{QUERY_STRING} !(id|dep)= [NC]
RewriteRule ^([0-9a-zA-Z-]+)/?$ index.php?id=$1 [NC,L,QSA]
那太完美了!(一旦你看到它,它就会变得简单)