我有一个.htaccess
文件,使用mod_rewrite将旧网站的网址重定向到新的网页等价物。可以在www.eastwood-whelpton.co.uk
查看新网站(目前仅适用于HTML5浏览器)。
到目前为止,我已经通过制作大量Redirect Permanent
语句来将每个旧页面翻译到新站点中的某个位置。
这一直有效,直到我需要为旧网站创建一个子域名(我需要保留)。以前,它只是在/old/
文件夹中,但Google仍在抓取它,尽管Robots.txt不允许这样做。为了解决这个问题,我把它放在子域“旧”中。
现在的问题是,访问old.eastwood-whelpton.co.uk/about.htm
这样的网页仍会尝试重定向到old.eastwood-whelpton.co.uk/about/about.php
- 这是新网站上的。{/ p>
这是我的HTACCESS文件的片段。我只需要重定向旧的“www”页面,而不是“旧”子域中的旧页面。
RewriteEngine on
RewriteCond %{HTTP_HOST} ^eastwood-whelpton [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
DirectoryIndex index.php
Redirect permanent /index.htm /index.php
Redirect permanent /index.html /index.php
Redirect permanent /yachthire.htm /holidays/sailingholidays.php
Redirect permanent /yachts.htm /about/thefleet.php
Redirect permanent /handover.htm /training/handover.php
Redirect permanent /holiday.htm /holidays/familyholidays.php
答案 0 :(得分:1)
不要混合它们!无论你有Redirect
什么,你的RewriteRule
指令都会执行。
请改为:
我已将您的Redirects
更改为RewriteRule
并稍微调整一下。已添加,
RewriteCond%{HTTP_HOST} ^旧[NC]
RewriteRule ^ - [L]
这不会重定向您的任何old
网站网址。
以下是整体:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^old [NC]
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} ^eastwood-whelpton [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
DirectoryIndex index.php
ReWriteRule index\.html? /index.php [L,R=301]
ReWriteRule yachthire\.htm /holidays/sailingholidays.php [L,R=301]
ReWriteRule yachts\.htm /about/thefleet.php [L,R=301]
ReWriteRule (handover)\.htm /training/$1.php [L,R=301]
ReWriteRule (holiday)\.htm /holidays/family$1s.php [L,R=301]