我的htaccess文件中有我的实时网站:
Options +MultiViews FollowSymLinks
RewriteEngine On
RewriteBase /
#301 redirect for all pages to use www
RewriteCond %{HTTP_HOST} !^(www\.|$) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
然而,当我在我的本地服务器上进行测试时,我必须手动将其更改为:
#Options +MultiViews FollowSymLinks
RewriteEngine On
RewriteBase /
#301 redirect for all pages to use www
#RewriteCond %{HTTP_HOST} !^(www\.|$) [NC]
#RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
是否有通过htaccess的自动方式,我可以根据当前的服务器IP打开和关闭东西?我的测试服务器是127.0.0.1
答案 0 :(得分:1)
您可以使用基于%{REMOTE_ADDR}
的重写条件:
#301 redirect for all pages to use www
RewriteCond %{REMOTE_ADDR} !=127.0.0.1
RewriteCond %{HTTP_HOST} !^(www\.|$) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
仅当IP不等于127.0.0.1