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 - Fatal编程技术网

如何从特定域重定向.htaccess?

如何从特定域重定向.htaccess?,.htaccess,redirect,.htaccess,Redirect,我在站点的.htaccess文件的根目录中有以下指令: # redirect to contact page redirectMatch 301 ^(/about)/?$ /contact/ 但是,该站点还承载其他几个域,这些域在根文件夹中显示为它们自己的目录。例如,http://mysite.com/anothersite/显示与http://anothersite.com 因此,重定向规则在编写时也会重定向http://anothersite.com/about/至http://anoth

我在站点的
.htaccess
文件的根目录中有以下指令:

# redirect to contact page
redirectMatch 301 ^(/about)/?$ /contact/
但是,该站点还承载其他几个域,这些域在根文件夹中显示为它们自己的目录。例如,
http://mysite.com/anothersite/
显示与
http://anothersite.com

因此,重定向规则在编写时也会重定向
http://anothersite.com/about/
http://anothersite.com/contact/


如何在根
.htaccess
文件中重写指令,使其仅适用于
http://mysite.com/about/

类似的方法应该可以工作:

RewriteCond %{HTTP_REFERER} ^.*mysite.com.*$ 
RewriteRule ^(/about)/?$ /contact/   [R=301,L]
试一试

以上内容仅适用于mysite.com。包括所有mysite子域,如www.etc和mysite.com使用

RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9-]+\.)?mysite\.com$ 
RewriteRule ^about/$ /contact/   [R=301,L]

我修改了最后一条规则来修正打字错误,还包括了普通的mysite.com域。让我知道重定向是否有效(运行Fiddler等以捕获HTTP流量)。如果没有,您的.htaccess中可能存在其他可能会干扰的规则-将它们全部注释掉,然后自己尝试验证。
RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9-]+\.)?mysite\.com$ 
RewriteRule ^about/$ /contact/   [R=301,L]