我因某种原因继承的网站是用www-以及www。
设置的为了澄清,这两个网址都有效:
我希望使用 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 :(得分: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]