htaccess request forwarding if internal ip

后端 未结 3 1635
青春惊慌失措
青春惊慌失措 2021-01-17 04:50

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?

相关标签:
3条回答
  • 2021-01-17 05:26
    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.

    0 讨论(0)
  • 2021-01-17 05:31

    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]
    
    0 讨论(0)
  • 2021-01-17 05:32

    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]

    0 讨论(0)
提交回复
热议问题