将网址重写为小写的最快方法?

发布于 2024-09-27 23:49:40 字数 184 浏览 2 评论 0原文

我正在寻找一种方法,最好使用 .htaccess 在用户输入大写字母时重写 url。

例如,URL 可以是 website.com/pagename

,用户类型可以是 website.com/PageName 或 website.com/PAGENAME

在不减慢页面加载速度的情况下,最好的方法是什么?

I'm looking for a way, preferably with .htaccess to rewrite a url when a user types in something with a capital.

For example, the url could be website.com/pagename

and the usertypes in website.com/PageName or website.com/PAGENAME

Whats the best way to do with without slowing down page load?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

花间憩 2024-10-04 23:49:40

您可以执行 HTTP 重定向(通过 Apache):

RewriteEngine on
RewriteMap lowercase int:tolower
RewriteCond $1 [A-Z]
RewriteRule ^/(.*)$ /${lowercase:$1} [R=301,L]

或者在 PHP 中进行处理:

$_SERVER['REQUEST_URI']=strtolower($_SERVER['REQUEST_URI']);

HTTP 重定向实际上不如 PHP 解决方案那么有效。

You can either do an HTTP redirect (via Apache):

RewriteEngine on
RewriteMap lowercase int:tolower
RewriteCond $1 [A-Z]
RewriteRule ^/(.*)$ /${lowercase:$1} [R=301,L]

or do the processing in PHP:

$_SERVER['REQUEST_URI']=strtolower($_SERVER['REQUEST_URI']);

HTTP redirection isn't really as efficient as the PHP solution.

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