Want to redirect all visitors except for me

前端 未结 4 850
别跟我提以往
别跟我提以往 2021-02-01 07:24

Basically I\'m about to start work on a site and I\'d like something that I can add into my .htaccess file (or elsewhere) that\'ll work like this pseudo code: (my ip will be in

4条回答
  •  青春惊慌失措
    2021-02-01 07:59

    That would be something like:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
    
    RewriteCond %{REQUEST_URI} !/mypage\.html$  
    
    RewriteRule .* http://www.anothersite.com/mypage.html [R=302,L]
    

    As Andrew points out, the %{REQUEST_URI} condition avoids infinite loop if you redirect to the same domain.

    As Xorax comments almost 9 years later:

    You should not use REMOTE_HOST, it will fail in many case. You should use REMOTE_ADDR.
    Cf "difference between REMOTE_HOST and REMOTE_ADDR"

提交回复
热议问题