可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have an address on my site like so:
http://www.example.com/lookup?q=http%3A%2F%2Fgigaom.com%2F2010%2F10%2F10%2Fangry-birds-for-windows7-phone-dont-count-on-it%2F
In this example, the dot in the 'gigaom.com' part of the query string is screwing with lighttpd and my rewrite rules. I get a 404 with the dot in, no 404 if I take the dot out. My rewrite rules are below. In case it makes a difference, I'm using symfony 1.4.
If anyone could shed some light on this problem it would be much appreciated!
url.rewrite-once = ( "^/(.*\..+)$" => "$0", "^/(.*)\.(.*)" => "/index.php", "^/([^.]+)$" => "/index.php/$1", "^/$" => "/index.php" )
For anyone having trouble with lighttpd and symfony (I know you're out there, cause there are plenty of unresolved threads on the issue) I ended up solving and answering it below.
回答1:
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!
回答2:
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