Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess htaccess:如何重写特定的GET变量?_.htaccess_Mod Rewrite - Fatal编程技术网

.htaccess htaccess:如何重写特定的GET变量?

.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=福特 现

对于主菜单,我有大约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=福特

现在假设我知道我使用的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]
那太完美了!(一旦你看到它,它就会变得简单)