Trailing dots being stripped from URL

2019-07-28 12:19发布

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条回答
太酷不给撩
2楼-- · 2019-07-28 12:54

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!

查看更多
登录 后发表回答