Redirect all requests to subdirectory except a few ip addresses

前端 未结 1 1312
天涯浪人
天涯浪人 2021-01-15 20:10

This question attempts to combine knowledge gained from some previous answers on SO, so do not mark as a duplicate unless the answer is meets the all of criteria about to be

1条回答
  •  野的像风
    2021-01-15 20:55

    How about:

    RewriteEngine On
    
    # for #2
    RewriteCond %{REMOTE_ADDR} !123\.45\.67\.89$
    RewriteCond %{REMOTE_ADDR} !123\.45\.67\.90$
    
    # for #1 and #3 and #4
    RewriteCond %{REQUEST_URI} !^/website/ [NC]
    RewriteRule ^(.*)$ http://www.example.com/website/$1 [R=302,L]
    

    For #2 you want to replace the 123\.45\.67\.89 etc with the IP addresses that you want not to be redirected.

    For #4, the R=301 needed to be changed to R=302

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