mod-rewrite - Lighttpd 配置,. (点)在我的查询字符串中导致 404

标签 mod-rewrite symfony1 url-rewriting lighttpd

我的网站上有这样一个地址:

http://www.example.com/lookup?q=http%3A%2F%2Fgigaom.com%2F2010%2F10%2F10%2Fangry-birds-for-windows7-phone-dont-count-on-it%2F

在此示例中,查询字符串“gigaom.com”部分中的点破坏了 lighttpd 和我的重写规则。我得到带点的 404,如果我去掉点,则没有 404。我的重写规则如下。以防万一,我使用的是 symfony 1.4。

如果有人能阐明这个问题,我们将不胜感激!

url.rewrite-once = (
    "^/(.*\..+)$" => "$0",
    "^/(.*)\.(.*)"    => "/index.php",
    "^/([^.]+)$"      => "/index.php/$1",
    "^/$"             => "/index.php"
  )

对于任何遇到 lighttpd 和 symfony 问题的人(我知道你在那里,因为这个问题上有很多 Unresolved 线程)我最终在下面解决并回答了它。

最佳答案

好的,在以下工具的帮助下进行大量调试之后:

debug.log-request-handling = "enable"

^^ 当您尝试在 lighttpd 中调试重写规则时,这是一个救星! (它为我记录了一切到/var/log/lighttpd/error.log)

我想通了。对于所有无法让 symfony 与 lighttpd 一起工作的人(包括点问题!),这里有一组工作规则:

url.rewrite-once = (
    "^/(js|images|uploads|css|sf)/(.*)" => "$0", # we want to load these assets as is, without index.php
    "^/[a-zA-Z_-]+\.(html|txt|ico)$" => "$0", # for any static .html files you might be calling in your web root, we don't want to put the index.php controller in front of them
    "^/sf[A-z]+Plugin.*" => "$0", # don't want to mess with plugin routes
    "^/([a-z_]+)\.php(.*)\.(.*)$" => "/$1.php$2.$3", # same concept as rules below, except for other applications/environments (backend.php, backend_dev.php, etc)
    "^/([a-z_]+)\.php([^.]*)$" => "/$1.php$2", # see comment right above this one
    "^/(.*)\.(.*)$"    => "/index.php/$1.$2", # handle query strings and the dot problem!
    "^/([^.]+)$"      => "/index.php/$1", # general requests
    "^/$"             => "/index.php" # the home page
  )

如果有人有更多问题,请在这里发帖。谢谢!

关于mod-rewrite - Lighttpd 配置,. (点)在我的查询字符串中导致 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3965651/

相关文章:

.htaccess - web.config 中的 URL 重写不适用于子目录中的 Slim PHP API

.htaccess - htaccess seo url 对\and/友好

apache - .htaccess - 将所有重定向到根文件夹或子文件夹的 index.php

regex - 如何使用 htaccess 将多个域重定向到除 1 个目录之外的另一个域?

php - 伪造 cookie 的 'path' - 通过 .htaccess/javascript/或其他方式?

php - 交响乐 : secure delete link with CSRFProtection

forms - 多对多对嵌入式形式

mod-rewrite - 使用 mod_rewrite 强制 SSL/HTTPS

php - 无法重新声明类 sfconfig

seo - 使用 HTTP_HOST 在 umbraco 中生成完整的规范 URL