Apache mod_rewrite ending periods

旧时模样 提交于 2020-01-01 19:03:05

问题


I am trying to better understand Apache's mod_rewrite, and am having unexpected results. I've tried many different expressions, but nothing seems to behave how I understand it should.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.*)$ index.php?route=$1 [QSA,L]

Using www.domain.com/item1/item2/item3 yields item1/item2/item3
Using www.domain.com/item1/item2/item3.php yields item1/item2/item3.php
Using www.domain.com/item1/item2/item3........... yields item1/item2/item3

Why is it not item1/item2/item3...........?

Strangely, if the URL is www.domain.com/item1/item2/item3..........a, the route is what I expect, item1/item2/item3..........a

I've tried a few other regular expressions, but they act similarly.

Thank you.


回答1:


While I still haven't found any documentation explaining why Apache/.htaccess/mod_rewrite behaves this way, I do have an alternative, in case anyone comes across this.

Instead of using .htaccess to pass the requested filename into a querystring variable, like route in my question above, in PHP there are some server variables that can be used. So, I changed my logic in index.php from reading the querystring to:

trim( $_SERVER['REDIRECT_URL'], "/" );

The REDIRECT_URL (and REQUEST_URI) server variables will retain the trailing dots, and the trim will get the leading and trailing slashes off, similar to what happens with the rewrite rule.




回答2:


I've got the same problem and it seems like a bug of Apache on Windows platform. However, it works on Linux.

https://issues.apache.org/bugzilla/show_bug.cgi?id=48687



来源:https://stackoverflow.com/questions/11144079/apache-mod-rewrite-ending-periods

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