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 Mod_rewrite将特定IP重定向到页面_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

.htaccess Mod_rewrite将特定IP重定向到页面

.htaccess Mod_rewrite将特定IP重定向到页面,.htaccess,mod-rewrite,redirect,.htaccess,Mod Rewrite,Redirect,我一直在试图让我的网站重定向到一个特定的网页特定的IP 在my.htaccess文件中使用以下命令 RewriteEngine On RewriteBase / RewriteCond %{REMOTE_HOST} ^138\.91\.49\.132$ RewriteRule .* http://www.anothersite.com/mypage.html [R=302,L] IP 138.91.49.132应重定向。没有任何内容被重定向 当我用这个的时候 RewriteEngine On

我一直在试图让我的网站重定向到一个特定的网页特定的IP

在my.htaccess文件中使用以下命令

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} ^138\.91\.49\.132$
RewriteRule .* http://www.anothersite.com/mypage.html [R=302,L]
IP 138.91.49.132应重定向。没有任何内容被重定向

当我用这个的时候

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^138\.91\.49\.132$
RewriteRule .* http://www.anothersite.com/mypage.html [R=302,L]
除138.91.49.132之外的所有内容都应重定向。一切都被重定向


这里到底发生了什么,让我非常沮丧。。。我做错什么了吗?

您需要使用
远程地址来代替:

RewriteEngine On

RewriteCond %{REMOTE_ADDR} ^138\.91\.49\.132$
RewriteRule (.*) http://www.anothersite.com/mypage.html [R=301,L]

我通过使用HTTP:CF-CONNECTING-IP使其工作,因为Cloudflare CDN似乎正在中断RewriteCond%{REMOTE_ADDR}的使用

RewriteCond %{HTTP:CF-CONNECTING-IP} ^(212\.219\.11\.6)$
RewriteRule (.*) http://lol.awebsite.co.uk [R=301,L]

感谢阿努巴瓦把我带到这个阶段。

不幸的是,这似乎没有任何效果。。。当从系统加载带有该IP的我的站点时,它仍然没有重定向..请确保这是您的第一条规则,并且.htaccess正在工作。我知道htaccess可以工作,因为我可以在删除该规则并用您提供的代码替换它时,使用RewriteCond%{HTTP_HOST}^mywebsite.co.uk RewriteRule(.[R=301,L]。它不工作。好吧,那么你确定这个IP确实是Apache看到的吗?(查看apacheaccess.log)我非常担心,根据日志,这是正确的ip。