如何解决htaccess将特定IP地址重定向到文件
我有一个要安装wordpress的域,但是我希望看到正在建设中的wordpress index1.php仅适用于我的IP地址。 同时,其他访客将继续正常看到index.html。
重定向:
- 从IP 1.2.3.4请求到domain.com的请求重定向到domain.com/index1.php
- 从其他对domain.com的ips请求重定向到domain.com/index.html
我试图通过修改.htaccess来做到这一点
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4
RewriteRule ^(.*)$ /index1.php [L]
我尝试了几种变体,但没有人能按预期工作
RewriteRule ^(.*\.html)$ /index1.php [L]
或
RewriteRule ^(.*\.html)$ /index1.php [L]
但这可能是重写条件。
解决方法
具有这种方式:
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} =1.2.3.4
RewriteRule ^(?:index\.html)?$ index1.php [L,NC]
RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4$
RewriteRule ^(?:index1\.php)?$ index.html [L,NC]
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteCond %{REMOTE_ADDR} =1.2.3.4
RewriteRule . index1.php [L]
RewriteRule . index.html [L]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。