htaccess request forwarding if internal ip

我的未来我决定 提交于 2019-12-01 12:52:36

问题


Is there a possible htaccess directive that can transparently forward request from index.php to index_internal.php if the request is coming from an internal ip range?


回答1:


RewriteEngine on

RewriteCond %{REMOTE_ADDR} ^192\.168\.1\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.15\.
RewriteRule ^index\.php$ index_internal.php [R,NC,QSA,L]

What this does:

start mod_rewrite engine (you may have that already)

if (client IP address starts with "192.168.1." [or]

client IP address starts with "10.15.")

and page name is index.php ([n]ot [c]ase sensitive), [r]edirect to index_internal.php, [q]uery [s]tring [a]ppend (i.e. index.php?foo=bar becomes index_internal.php?foo=bar), [l]eave processing.

Modify as needed for IP address blocks.




回答2:


Something like this should do it (obviously change the IP address to match your network):

RewriteCond %{REMOTE_ADDR} ^192\.168\.
RewriteRule index.php index_internal.php

If you want an actual header then make it RewriteRule index.php index_internal.php [L,R,QSA]




回答3:


ok here's my code (no redirect) based on wikipedia's private network list

RewriteEngine on
RewriteCond %{REMOTE_ADDR} ^10\. [OR]
RewriteCond %{REMOTE_ADDR} ^172\.[1-3]{1}\d{1}\. [OR]
RewriteCond %{REMOTE_ADDR} ^192\.168\.
RewriteRule ^index\.php index_internal.php [NC,QSA,L]


来源:https://stackoverflow.com/questions/258680/htaccess-request-forwarding-if-internal-ip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!