Lighttpd configuration, . (dots) in my query string cause 404

半城伤御伤魂 提交于 2019-12-04 20:14:01

OK so after much debugging with the help of:

debug.log-request-handling = "enable"

^^ This is a lifesaver for when you're trying to debug rewrite rules in lighttpd! (it logged everything for me to /var/log/lighttpd/error.log)

I've figured it out. For all those people having trouble getting symfony to work with lighttpd (including the dot problem!) here's a working set of rules:

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
  )

If anyone has more trouble, post here. Thanks!

sultan

I am using PHP, MySQL, and .htaccess file for rewriting rules. Just sharing so others can also benefit.

My previous rule:

RewriteRule ^([^/\.]+)/([^/\.]+).html$ detail.php?name=$1&id=$2 [L]

It was working with this result: http://www.sitecliff.com/Yahoo-UK/4.html

I wanted the website name instead of the title in the url. After surfing the net, I figured out that the dot is causing the problem as you mentioned above.

"^/(.*)\.(.*)$"    => "/index.php/$1.$2", # handle query strings and the dot problem!

So I changed the rule to:

RewriteRule ^([^/]+)$ detail.php?url=$1 [L]

After this, I got my desired result: http://www.sitecliff.com/yahoo.com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!