从 URL 中删除尾随点
我有一个网址 - http://callisto/news/1st_February_is_here...
- 它有三个尾随点,但是当它通过 mod_rewrite 并到达脚本时(在 $_GET 中) )点已被删除(但字符串的其余部分没问题)。
这是 htaccess 规则:
RewriteRule ^([^/]+)/(.*)$ index.php?__action=site&__filter=$1&__page=$2 [L,QSA]
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您正在使用帖子标题或类似的内容作为 URI 中的第三个位置。由于使用此方法您的 URI 中可能会出现许多其他“破坏”字符,因此我建议您在将标题附加到 URI 之前先清理标题,并将相同的清理后的字符串放入数据库中以供参考。
删除所有非字母数字的字符,并用连字符“-”替换空格——这将确保您不会进一步混淆任何内容,也不会遇到任何浏览器特定的问题,从而使您的 URI 无法正常工作。
运行上面的代码将会清理你的标题。
应该变成:
或者类似的东西。我建议使用连字符而不是下划线的唯一原因是,有时我会遇到在 URI 中传递下划线的问题。
另外,我认为您会发现这是 WordPress 使用的方法 - 很可能与您看到此问题的原因相同。
GL!
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.
Running the code aboce will clean your title.
Should become:
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!