2012-11-25 62 views
0

所以我有一種奇怪的麻煩。我從在htaccess中重寫問題

mysite.com/brand.php?brand=example&ref=ex1 

mysite.com/brand/example/ex1 

重寫規則,我設法做到這一點,但也有另外一個問題:當你輸入:

mysite.com/brand/example/ex1.html 

mysite.com/brand/example/ex1.php 

我得到這個:

mysite.com/brand/example/ex1?ref=ex1.php&brand=example 

任何人都可以告訴我爲什麼我得到這個重定向以及如何擺脫它?

我嘗試這樣做:

RedirectMatch ^brand/([A-Za-z0-9-\.\_]+)/([A-Za-z0-9-\.\_]+)php$ /brand/$1/$2 

或本:

RedirectMatch ^brand/([A-Za-z0-9-\.\_]+)/([A-Za-z0-9-\.\_]+)\.php$ /brand/$1/$2 

,但它根本不起作用。

請大家幫幫我!

回答

0

我會用mod_rewrite此:

RewriteEngine On 
RewriteCond %{REQUEST_URI} =/brand.php 
RewriteCond %{QUERY_STRING} ^brand=([^&]+&ref=(.+)$ 
RewriteRule .* /brand/%1/%2? [L,R] 

RewriteRule當兩個RewriteCond有效僅適用。第一個RewriteCond比較請求URL爲/brand.php,第二個匹配正則表達式與查詢字符串相匹配,並將匹配分別存儲在%1%2中。

RewriteRule是使用查詢字符串中匹配的部分重寫的URL。

+0

請問你能說出這段代碼的作用嗎? –

+0

@AlickDikan已更新答案... –