Trailing dots being stripped from URL

巧了我就是萌 提交于 2020-01-15 12:37:13

问题


I've got a url - http://callisto/news/1st_February_is_here... - which has three trailing dots, but by the time it gets passed through mod_rewrite and reaches the script (in $_GET) the dots have been removed (but the rest of the string is OK).

This is the htaccess rule:

RewriteRule ^([^/]+)/(.*)$ index.php?__action=site&__filter=$1&__page=$2 [L,QSA]

Thanks.


回答1:


I take it you are using the title of a post or something similar as the third position in your URI. Due to the fact that you could probably have a lot of other 'breaking' characters come through your URI with this method I would suggest that you cleanse the title before appending it to the URI and place the same cleansed string into your database for reference.

Remove any characters that aren't alphanumeric and replace spaces with a hyphen '-'--this will ensure that you don't confuse anything further down the line or bump into any browser specific issues that keep your URI from working.

$title = '1st February is here...';
$clean_title = preg_replace('/[^a-zA-Z0-9\s]/', '', $title);
$finished_title = str_replace(' ', '-', $clean_title);

Running the code aboce will clean your title.

http://callisto/news/1st_February_is_here...

Should become:

http://callisto/news/1st-February-is-here

Or something similar. The only reason I suggest a hyphen instead of an underscore is that I have, on occasion, had issues with underscores being passed in the URI.

Also, I think you will find this is the method that Wordpress employs--most likely for the same reason that you are seeing this issue.

GL!



来源:https://stackoverflow.com/questions/2280805/trailing-dots-being-stripped-from-url

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