2016-04-12 5 views
0

私はリダイレクトする必要がある2つのパターンがあります。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] 

です。 2番目のリダイレクトを有効にするにはどうすればよいですか?

答えて

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 =(。+)$'に変更してみてください –

関連する問題