将所有ip重定向到维护页面,但某些ips除外

时间:2015-06-18 09:04:27

标签: apache .htaccess symfony

在发布我的Symfony项目的新版本时,我需要使用apache将所有外部IP地址重定向到maintenance.html页面(它位于symfony web目录中)。

以下是我为此目的创建的virtualhost文件配置,但是:

  • 当我从外部ip开始时,我得到403 Forbidden
  • 当我从localhost出发时,我得到同样的403 Forbidden
  

虚拟主机文件

<VirtualHost *:80>
    ServerName myservername
    ServerAlias www.myservername
    ServerAdmin webmaster@localhost
    DocumentRoot /path/to/my/symfony/project/web

    RewriteEngine on
    # if request not coming from localhost
    RewriteCond %{REMOTE_ADDR} !127.0.0.1
    # if request not maintenance.html page
    RewriteCond %{REMOTE_URI} !/maintenance.html [NC]
    # if request not image
    RewriteCond %{REMOTE_URI} !\.(jpe?g?|png|gif|ico) [NC]
    # if request not css file
    RewriteCond %{REMOTE_URI} !\.(css) [NC]
    # Redirect to maintenance.html page
    RewriteRule .* /maintenance.html [R=302,L]

    <Directory /path/to/my/symfony/project/web>
        # Ignore .htaccess files
        AllowOverride None
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/maintenance-error.log
    CustomLog ${APACHE_LOG_DIR}/maintenance-access.log combined
</VirtualHost>

我做错了什么?

  

技术版

apache2 -v 2.4.7   (needs to work on 2.2 too)

1 个答案:

答案 0 :(得分:1)

mod_rewrite不知道%{REMOTE_URI}变量。可能你的意思是%{REQUEST_URI}

相关问题