2016-04-12 80 views
0

我有兩種需要重定向的模式。帶有URL參數的Htaccess - 訂單

www.example.com/tag/value to www.example.com/recipe-tag/value 
www.example.com/?tag=value to www.example.com/recipe-tag/value 

這是我目前的.htaccess

RewriteEngine On 
RewriteBase/
RewriteRule ^tag/(.*) http://www.example.com/recipe-tag/$1 [R=301,L] 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 

這適用於第一個重定向。我應該怎麼做第二個重定向工作?

回答

1

您必須使用條件來檢測查詢字符串。試試這個。

RewriteEngine On 
RewriteBase/

RewriteCond %{QUERY_STRING} tag=(.+)$ 
RewriteRule^http://www.example.com/recipe-tag/%1? [R=301,L] 

RewriteRule ^tag/(.*) http://www.example.com/recipe-tag/$1 [R=301,L] 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 

讓我知道如何適合你。

+0

作品。非常感謝 ! – vanipriya

+0

這是一個問題。我只希望在www.example.com/?tag=value這個模式中選擇模式。 即使URL中其他地方存在「標籤」,也會選取該標籤。如何驗證這種模式? – vanipriya

+0

嘗試將'tag =(。+)$'改爲^^tag =(。+)$' –