2012-02-07 26 views
0

對於一個主菜單我已經得到了大約3個header header catagoty的 我喜歡靜態重寫它們。htaccess:如何重寫特定的GET變量?

這是我現在使用的代碼:

RewriteCond %{QUERY_STRING} !dep= [NC]  
RewriteRule ^([0-9a-zA-Z-]+)/?$ index.php?dep=$1 [NC,L,QSA] 

www.hello.com/car/會給// $ _ GET VAR // DEP =車

簡單嗎?我將如何讓:www.hello.com/car/ford/
讓 '迴歸' DEP =汽車& ID =福特

現在,讓我們說,我知道3我使用paramters? '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 
*/ 

回答

2

簡單我將如何讓:www.hello.com/car/ford/讓 '迴歸' DEP =汽車& ID =福特

添加呢?您的規則後,排除:

RewriteRule ^([0-9a-zA-Z-]+)/([0-9a-zA-Z-]+)/?$ index.php?dep=$1&id=$2 [NC,L,QSA] 

現在,讓我們說,我知道3我使用paramters 'DEP?'。你怎麼寫:

你需要改變你的條件,因爲你需要檢查「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] 
+0

更多那就完美了! (一旦你看到它就簡單了) – Rob 2012-02-07 01:47:12