重定向所有请求子目录,除了少数的IP地址 [英] Redirect all requests to subdirectory except a few ip addresses
问题描述
此问题将尝试合并从SO一些previous答案获得的知识,所以不要标记为重复,除非答案是满足了所有即将被给定的标准。
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 given.
这就是我想做的事:
我需要暂时的.htaccess访问者重定向到我的网站,以一个克隆副本,这样我可以在现有的网站进行修改。
因此,我有以下需求:
1.所有用户的请求/(.*)应该被重定向到子目录/网站/ $ 1(即如果有人请求的index.php它应该去/website/index.php)
2.如果用户是从三个具体IPS一个请求不应该被重定向,并且应到文件(即,如果我要求的index.php它应该去的index.php)
3.说重定向也应强制使用WWW(带或不带WWW即请求,应重定向到www.example.com/website~~V)
4.说重定向应该是一些各种各样的临时重定向(正常的网站将只下降了两天的)
This is what I want to do:
I need to temporarily .htaccess redirect visitors to my site to a clone copy so that I can make modifications on the existing site.
Therefore, I have the following needs:
1. All users requests /(.*) should be redirected to sub-directory /website/$1 (ie if someone requests /index.php it should go to /website/index.php)
2. If the user is from one of three specific ips the request should not be redirected, and should go to the file (ie if I request /index.php it should go to /index.php)
3. Said redirection should also force the use of www (ie requests with or without www, should be redirected to www.example.com/website)
4. Said redirection should be a temporary redirect of some sorts (the normal site will only be down for a couple of days)
这是我目前的code:
This is my current code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "http\:\/\/www\.example\.com\/website\/" [R=301,L]
它符合标准1,3和4。我只是需要帮助,调整为不定向三个特定的IP地址。
It meets criteria 1,3, and 4. I just need help adjusting it to not redirect the three specific ip addresses.
有什么想法就如何将#2?
Any thoughts as to how to incorporate #2?
推荐答案
怎么样:
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]
有关#2你要替换 123 \ 0.45 \ 0.67 \ 0.89
等与你想不被重定向的IP地址。
For #2 you want to replace the 123\.45\.67\.89
etc with the IP addresses that you want not to be redirected.
有关#4, R = 301
需要改为 R = 302
这篇关于重定向所有请求子目录,除了少数的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!