在 mod_rewrite 规则中转换为小写

发布于 2024-09-03 02:13:51 字数 679 浏览 3 评论 0原文

我希望像 server.com/foo 这样的 URL 不区分大小写。 但是 server.com/foo 实际上将 mod_rewrite'd 到 server.com/somedir/foo

(假设“somedir”中的所有文件都是小写的。)

所以问题是,如何完成如下所示的 mod_rewrite:

RewriteRule  ^([^/]+)/?$  somedir/convert_to_lowercase($1)

PS:这是一个方便的 mod_rewrite 备忘单 - http://dreev.es/modrewrite - 尽管它无法回答这个问题特别的问题。

PP:感谢 蜜蜂伊格纳西奥 感谢所有对此的帮助。 另外,这是一个相关问题: RewriteMap 激活

I would like URLs like server.com/foo to be case-insensitive.
But server.com/foo actually gets mod_rewrite'd to server.com/somedir/foo

(Assume that all the files in "somedir" are lower case.)

So the question is, how to accomplish a mod_rewrite like the following:

RewriteRule  ^([^/]+)/?$  somedir/convert_to_lowercase($1)

PS: Here's a handy mod_rewrite cheat sheet -- http://dreev.es/modrewrite -- though it fails to answer this particular question.

PPS: Thanks to
Bee
and
Ignacio
for all the help with this.
Also, here's a related question:
RewriteMap activation

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

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

发布评论

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

评论(3

叹梦 2024-09-10 02:13:51

首先,将以下行放入 .conf 文件的 部分。
(对于我来说,它位于 /etc/httpd/vhosts.d/00foo.conf。)

RewriteMap lc int:tolower 

您可以将 lc 替换为您想要的任何名称。
然后重新启动 apache,您可以使用 sudo service httpd restart 来完成此操作。

最后,将其添加到您的 .htaccess 文件中:

RewriteRule ^/(.*)$ /${lc:$1} 

First, put the following line in the <VirtualHost> section of your .conf file.
(For me that lives at /etc/httpd/vhosts.d/00foo.conf.)

RewriteMap lc int:tolower 

You can replace lc with any name you want.
Then restart apache, which you can do with sudo service httpd restart.

Finally, add this in your .htaccess file:

RewriteRule ^/(.*)$ /${lc:$1} 
椒妓 2024-09-10 02:13:51
RewriteMap tolower int:tolower
RewriteRule  ^([^/]+)/?$  somedir/${tolower:$1}
RewriteMap tolower int:tolower
RewriteRule  ^([^/]+)/?$  somedir/${tolower:$1}
苯莒 2024-09-10 02:13:51

出于 SEO 目的,我会将其设为 301 重定向,而不是 URL 重写:

RewriteMap tolower int:tolower
RewriteRule  ^([^/]+)/?$  somedir/${tolower:$1} [R=301,L]

I would make it a 301 redirect, NOT a URL rewrite, for SEO purposes:

RewriteMap tolower int:tolower
RewriteRule  ^([^/]+)/?$  somedir/${tolower:$1} [R=301,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文