Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess重定向(如果不是子域)_.htaccess_Redirect_Subdomain - Fatal编程技术网

.htaccess重定向(如果不是子域)

.htaccess重定向(如果不是子域),.htaccess,redirect,subdomain,.htaccess,Redirect,Subdomain,我有一个.htaccess文件,使用mod_rewrite将URL从旧网站重定向到新网页。新网站可在www.eastwood-whelpton.co.uk上查看(目前仅适用于HTML5浏览器) 到目前为止,我通过制作大量的重定向永久性语句,将每个旧页面翻译到新站点的某个位置,实现了这一点 这一直有效,直到我需要为旧网站创建子域(我需要保留)。以前,它只是在文件夹/old/中,但尽管Robots.txt不允许,谷歌仍然会抓取它。为了解决这个问题,我把它放在子域“old”中 现在的问题是,访问诸如o

我有一个
.htaccess
文件,使用mod_rewrite将URL从旧网站重定向到新网页。新网站可在
www.eastwood-whelpton.co.uk
上查看(目前仅适用于HTML5浏览器)

到目前为止,我通过制作大量的
重定向永久性
语句,将每个旧页面翻译到新站点的某个位置,实现了这一点

这一直有效,直到我需要为旧网站创建子域(我需要保留)。以前,它只是在文件夹
/old/
中,但尽管Robots.txt不允许,谷歌仍然会抓取它。为了解决这个问题,我把它放在子域“old”中

现在的问题是,访问诸如
old.eastwood whelpton.co.uk/about.htm
之类的页面仍然会尝试重定向到新站点上的
old.eastwood whelpton.co.uk/about/about.php

这是我的HTACCESS文件的一个片段。我所需要的只是重定向旧的“www”页面,而不是“old”子域中的旧页面

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
首先,是来自

不要把它们混在一起!不管您有什么
重写规则
,您的
重定向
指令都将执行

改为这样做:

我已将您的
重定向
更改为
重写规则
,并对其进行了一些调整。他补充说,

重写cond%{HTTP_HOST}^old[NC]
重写规则^-[L]

这不会重定向任何
旧的
站点URL

全部内容如下:

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]
首先,是来自

不要把它们混在一起!不管您有什么
重写规则
,您的
重定向
指令都将执行

改为这样做:

我已将您的
重定向
更改为
重写规则
,并对其进行了一些调整。他补充说,

重写cond%{HTTP_HOST}^old[NC]
重写规则^-[L]

这不会重定向任何
旧的
站点URL

全部内容如下:

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]

杰出的它仍然有点零碎,可能是缓存和诸如此类的东西造成的,仅/yachts.htm重定向暂时可以正常工作,但我认为重写规则^-[L]是解决这个难题的关键。一旦我成功了,我会选择这个作为答案。谢谢@CJxD清除浏览器缓存一次。然后试试看。以防万一,重新启动你的Apache。好吧,我还是不能让它工作。唯一正确响应的是/yachts\.htm行。@CJxD我刚才已经更新了答案。。已在开始时删除了所有
/
。@CJxD from:
在目录和htaccess上下文中,在删除导致服务器指向当前重写规则的前缀(例如“app1/index.html”或“index.html”,具体取决于指令的定义位置)后,模式最初将与文件系统路径匹配.
非常好。它仍然有点零碎,可能是缓存和诸如此类的东西造成的,仅/yachts.htm重定向暂时可以正常工作,但我认为重写规则^-[L]是解决这个难题的关键。一旦我成功了,我会选择这个作为答案。谢谢@CJxD清除浏览器缓存一次。然后试试看。以防万一,重新启动你的Apache。好吧,我还是不能让它工作。唯一正确响应的是/yachts\.htm行。@CJxD我刚才已经更新了答案。。在开始时已删除了所有
/
。@CJxD from:
在目录和htaccess上下文中,在删除导致服务器指向当前重写规则的前缀(例如“app1/index.html”或“index.html”,具体取决于指令的定义位置)后,模式最初将与文件系统路径匹配。