RewriteCond/RewriteRule 具有不区分大小写和尾部斜杠功能吗?

发布于 2024-09-13 04:23:58 字数 398 浏览 2 评论 0原文

我遇到以下两行问题:

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+[^/])$ /$1.html [L]

目标:重定向“domain.tld/test/”(仅当 test.html 存在时),以便输出“domain.tld/test.html”的内容。

  • 如何使其不区分大小写:“domain.tld/Test”-> domain.tld/test.html **
  • 如何让它接受尾部斜杠:“domain.tld/test/”也应该有效,

谢谢!

** 我无法让 RewriteMap lowercase int:tolower 工作,感谢任何帮助。

I got problems with the following two lines:

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+[^/])$ /$1.html [L]

Goal: Redirecting "domain.tld/test/" (only if test.html exists) so that it outputs the contents of "domain.tld/test.html".

  • How to make this case-insensitive: "domain.tld/Test" -> domain.tld/test.html **
  • How to make it accept a trailing slash: "domain.tld/test/" should work, too

Thanks!

** I couldn't get RewriteMap lowercase int:tolower to work, any help appreciated.

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

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

发布评论

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

评论(2

听,心雨的声音 2024-09-20 04:23:58

使用 [NC] 进行不区分大小写的检查。

请参阅此处了解尾部斜杠问题:模式重写;网址末尾有/没有尾部斜杠吗?

Use [NC] for case insensitive checking.

See here for the trailing slash issue: Mode Rewrite; with/without trailing slash on end of url?

心碎无痕… 2024-09-20 04:23:58

试试这个:

RewriteRule (.+)/$ $1
RewriteCond %{DOCUMENT_ROOT}/${tolower:$1}.html -f
RewriteRule ^(.+[^/])$ /$1.html [L]

此外 RewriteMap只能在服务器配置或虚拟主机上下文中使用,但不能在 .htaccess 文件中使用。所以你需要在那里定义重写映射。

Try this:

RewriteRule (.+)/$ $1
RewriteCond %{DOCUMENT_ROOT}/${tolower:$1}.html -f
RewriteRule ^(.+[^/])$ /$1.html [L]

Furthermore RewriteMap can only be used in the server configuration or virtual host context but not in a .htaccess file. So you need to define the rewrite map there.

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