Apache htaccess重定向,IP除外
我尝试使用.htaccess 假设我的网站是example.com 我想重定向每个example.com/anypage.php或example.com/anyfolder 至example.com/construction.phpApache htaccess重定向,IP除外,apache,.htaccess,mod-rewrite,redirect,url-rewriting,Apache,.htaccess,Mod Rewrite,Redirect,Url Rewriting,我尝试使用.htaccess 假设我的网站是example.com 我想重定向每个example.com/anypage.php或example.com/anyfolder 至example.com/construction.php <!DOCTYPE html> <html lang="en"> <head> <title>example</title> <link rel="icon" href="favicon.ico"&g
<!DOCTYPE html>
<html lang="en">
<head>
<title>example</title>
<link rel="icon" href="favicon.ico">
<body>
<div>
<img src="construction.jpg"/>
</div>
</body>
</html>
但是有些IP不需要重定向,比如
123.0.1.xxx
和
123.0.2.3
这是我的construction.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>example</title>
<link rel="icon" href="favicon.ico">
<body>
<div>
<img src="construction.jpg"/>
</div>
</body>
</html>
但它重定向了我的IP地址。我的.htaccess中是否有任何问题?请立即尝试,我已删除该条件,否则它将正常工作!非常感谢。但IP不能同时为123.0.1.1和123.0.2.3。它应该是123.0.1.1或123.0.2.3。我不知道为什么删除[或]将起作用XDDOR标志使多个条件可选,在您的情况下,mod_rewrite仅在1个条件下处理规则=如果Ip 123456或Request_filename为foo.jpg。但是您的规则需要两个条件来重定向请求。是的,我认为对它们重新排序也不能解决问题。如果您有一个没有OR的条件,并且其他条件在一个块中设置了OR标志,则Mod_rewrite使用其中一个条件来运行规则。我非常感谢您在解决问题方面的帮助。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !construction\.(jpg|php)$
RewriteCond %{REMOTE_ADDR} !^123\.0\.1\.
RewriteCond %{REMOTE_ADDR} !^123\.0\.2\.3
RewriteRule ^(.*)$ http://example.com/construction.php [R=301,L]