从 URL 中删除尾随点

发布于 2024-08-22 14:32:09 字数 293 浏览 4 评论 0原文

我有一个网址 - 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断念 2024-08-29 14:32:09

我认为您正在使用帖子标题或类似的内容作为 URI 中的第三个位置。由于使用此方法您的 URI 中可能会出现许多其他“破坏”字符,因此我建议您在将标题附加到 URI 之前先清理标题,并将相同的清理后的字符串放入数据库中以供参考。

删除所有非字母数字的字符,并用连字符“-”替换空格——这将确保您不会进一步混淆任何内容,也不会遇到任何浏览器特定的问题,从而使您的 URI 无法正常工作。

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

运行上面的代码将会清理你的标题。

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

应该变成:

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

或者类似的东西。我建议使用连字符而不是下划线的唯一原因是,有时我会遇到在 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.

$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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文