【问题标题】:Apache2 doesn't properly redirect URLs with certain characters in themApache2 无法正确重定向包含某些字符的 URL
【发布时间】:2017-05-22 01:02:39
【问题描述】:

给定以下虚拟主机:

<VirtualHost *:80>
    ServerAdmin webmaster@domain.com
    ServerName subdomain.domain.com
    ServerAlias *.subdomain.domain.com

    DocumentRoot /var/www/project/web/

    <Directory /var/www/project/web/>
            Options FollowSymLinks
            AllowOverride All
    </Directory>

    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^.*subdomain\.domain\.com$ [NC]
    RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com$ [NC]
    RewriteRule ^(.*)$ http://subdomain.domain.com$1 [R=301,L]

    RewriteCond %{REQUEST_URI} !^/(static)/
    RewriteRule ^(.*)$ /index.php [L]

    ErrorLog /var/log/apache2/error_project.log
    LogLevel warn
    CustomLog /var/log/apache2/access_project.log vhost_combined
</VirtualHost>

我正在尝试将所有请求 除了 那些以 /static 开头的请求(CSS、JS 和图像所在的位置)重定向到主控制器 index.php ,它将处理到不同模块的路由。

一切正常,直到我尝试访问这样的链接:

http://subdomain.domain.com/view/10/Http%3A%2F%2Fnews.discovery.com%2Fspace%2Fnasa-installs-cosmic-ray-hunter

和 Apache2 显示一个 404 页面,请求永远不会到达 index.php 文件。用破折号之类的东西替换链接中的所有 %3A%2F 可以让它再次工作。

也试过用:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]

但同样的 404 也会发生。

【问题讨论】:

    标签: apache mod-rewrite


    【解决方案1】:

    根据手册,为了提高安全性,Apache 将拒绝所有包含编码斜线%2F 和 404 的 URL。

    为了禁用此行为,您需要将AllowEncodedSlashes 设置为OnNoDecode 的值,最好是NoDecode

    该指令需要全局放在服务器配置或虚拟主机定义中,它在 .htaccess

    中不起作用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-05
      • 1970-01-01
      • 2011-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多