2011-09-13 17 views
0

私が何らかの理由で継承したサイトは、www-とwwwの両方で設定されていました。htaccess redirect woes

明確にするためには、これらのURLの両方が動作します:

私はWWWにリダイレクトするWWW-を使用して、すべてのトラフィックを取得したいです。

私は次のhtaccessルールでそれを釘付けにしたと思っていましたが、動作していないようです。どんな助けでも大歓迎です!

RewriteEngine On 
RewriteCond %{HTTP_HOST} !^www.mcr.trinhall.cam.ac.uk$ [NC] 
RewriteRule ^(.*)$ http://www.mcr.trinhall.cam.ac.uk/$1 [L,R=301] 

フルの.htaccessファイルは、以下の通りです:

RewriteEngine On 
RewriteCond %{HTTP_HOST} !^www.mcr.trinhall.cam.ac.uk$ [NC] 
RewriteRule ^(.*)$ http://www.mcr.trinhall.cam.ac.uk/$1 [L,R=301] 

RedirectMatch 301 ^/wiki/International_Students http://www.mcr.trinhall.cam.ac.uk/prospective-students/international/ 
RedirectMatch 301 ^/wiki/McMenemy_Seminar http://www.mcr.trinhall.cam.ac.uk/academics/mcmenemy-seminars/ 
RedirectMatch 301 ^/wiki/Welfare http://www.mcr.trinhall.cam.ac.uk/welfare/counselling/ 
RedirectMatch 301 ^/wiki/Transportation http://www.mcr.trinhall.cam.ac.uk/prospective-students/getting-around/ 
RedirectMatch 301 ^/wiki/Grants http://www.mcr.trinhall.cam.ac.uk/college-support/grants-and-funding/ 
RedirectMatch 301 ^/wiki/Grants_and_Funding http://www.mcr.trinhall.cam.ac.uk/college-support/grants-and-funding/ 
RedirectMatch 301 ^/wiki/Cake http://www.mcr.trinhall.cam.ac.uk/welfare/peer-support/ 
RedirectMatch 301 ^/wiki/Disability_Access http://www.mcr.trinhall.cam.ac.uk/welfare/students-with-disabilities/ 
RedirectMatch 301 ^/wiki/Recycling_Instructions http://www.mcr.trinhall.cam.ac.uk/current-college-residents/green/ 
RedirectMatch 301 ^/wiki/Bateman_Street http://www.mcr.trinhall.cam.ac.uk/prospective-students/accommodation/ 
RedirectMatch 301 ^/wiki/Life_in_Cambridge http://www.mcr.trinhall.cam.ac.uk/prospective-students/eating-in-cambridge/ 
RedirectMatch 301 ^/wiki/Prospective_Students http://www.mcr.trinhall.cam.ac.uk/prospective-students/accommodation/ 
RedirectMatch 301 ^/wiki/Leslie_Stephen_Room http://www.mcr.trinhall.cam.ac.uk/college-facilities/function-rooms/ 
RedirectMatch 301 ^/wiki/Dining http://www.mcr.trinhall.cam.ac.uk/dining-in-college/formal-dinners/ 
RedirectMatch 301 ^/wiki/Mailing_list http://www.mcr.trinhall.cam.ac.uk/your-mcr/mailing-lists/ 
RedirectMatch 301 ^/wiki/MCR_Committee http://www.mcr.trinhall.cam.ac.uk/your-mcr/committee/ 
#RedirectMatch 301 ^/wiki/ http://www.mcr.trinhall.cam.ac.uk/ 

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

# END WordPress 

答えて

0

問題は、この行である:

RewriteCond %{HTTP_HOST} !^www.mcr.trinhall.cam.ac.uk$ [NC] 

あなたはあなたが達成したい場合は、ドット.文字をエスケープする必要がありますあなたが欲しいもの。正規表現では、ドット文字はすべての文字を意味します。あなたは現在の正規表現www.mcr.trinhall.cam.ac.ukだけでなく、www-mcr-trinhall-cam-ac-ukだけでなくwww8mcr8trinhall8cam8ac8ukなどと一致します - あなたは考えている。

RewriteCond %{HTTP_HOST} !^www\.mcr\.trinhall\.cam\.ac\.uk$ [NC] 

または非正規表現マッチ(プレーンな文字列の比較)を使用します:もちろん

RewriteCond %{HTTP_HOST} !=www.mcr.trinhall.cam.ac.uk [NC] 
+0

をドットをエスケープそれを解決するために

!私はそれがそれのような単純なものになると思った。ありがとうございました! – tallphil