2016-03-31 13 views
1

私のhtaccessは、場合によってはダブル301リダイレクトを生成することに気付きました。私のhtacessから二重301リダイレクトを削除しますか?

http://www.example.com/old_url
  • まず301(追加WWW)
  • その後301

(新しいURLに変更) http://www.example.com/new_urlにここに私のhtaccessファイルがある方法は次のとおりです。たとえば、あなたは http://example.com/old_urlそれ意志にアクセスしようとした場合セットアップ:

RewriteEngine On 

# Add www 
RewriteCond %{HTTP_HOST} ^example.com [nocase] 
RewriteRule ^(.*) http://www.example.com/$1 [last,redirect=301] 

# Do some url rewriting 
RewriteRule ^new_url_1$ new_url_1.php [NC,L] 
RewriteRule ^new_url_2$ new_url_2.php [NC,L] 

# Do the 301 redirections 
Redirect 301 /old_url_1 http://www.example.com/new_url_1 
Redirect 301 /old_url_2 http://www.example.com/new_url_2 

どのように私は改善のSEOのための301だけを持つことができますか?ありがとう!

答えて

0

mod_rewriteルールでRedirectディレクティブをミックスし、wwwルールの前に具体的なリダイレクトルールを保管しないでください:

RewriteEngine On 

## Unless directory, remove trailing slash 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)/$ /$1 [NE,R=302,L] 

# Do specific 301 redirections 
RewriteRule ^old_url_1$ http://www.example.com/new_url_1 [L,NC,R=301] 
RewriteRule ^old_url_2$ http://www.example.com/new_url_2 [L,NC,R=301] 

# Add www 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule^http://www.%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301] 

# Do some url rewriting 
RewriteRule ^new_url_1$ new_url_1.php [NC,L] 

RewriteRule ^new_url_2$ new_url_2.php [NC,L] 

試験前にブラウザのキャッシュをクリアすることを確認します。

+0

ありがとう、私はそれを試してみます。 'Redirect 301/old_url_1 http:// www.example.com/new_url_1'と' RewriteRule^old_url_1 /?$ http://www.example.com/new_url_1 [L、NC、R = 301]の違いは何ですか? ? –

+1

'RewriteRule'はmod_rewriteディレクティブで、' Redirect'は 'mod_alias'です。異なるモジュールが異なる時間に実行され、それらを一緒に混合すると問題が発生する可能性があります。 – anubhava

+0

そして、両者の具体的な違いはどうですか? "/?"を追加しました。オプションでは "L、NC"と表示されます。それは何か変わるのだろうか? –

関連する問題