RewriteRule 中的正则表达式,传递给引导 PHP 文件

发布于 2024-10-07 21:47:55 字数 613 浏览 0 评论 0原文

我正在尝试找出一种解决方案,将所有相关的 HTTP 请求传递到我的 index.php 引导文件。

我想要强制执行的两个规则是:

  • 任何目录、
  • 任何具有 .html.ajax 文件扩展名的文件(在任何目录中)。

这些文件或目录实际上都不存在——引导 PHP 文件将动态输出相关内容。


这是我当前的 .htaccess 文件

RewriteEngine on
Options +FollowSymLinks
#RewriteCond %{REQUEST_URI}$1 !-f
RewriteRule ^/?(.+(?:\.html?)?)$ index.php [L]
RewriteRule \.ajax$ index.php [L]

RewriteCond 已被注释掉,因为它似乎没有任何效果,并且使用正确的 RewriteRule 无论如何它都会过时(图像文件,javascript 文件等将不会与规则,因此不需要检查是否存在)。

我认为正则表达式专家可以轻松解决这个问题,另外一个优点是将这两个规则合并到一个正则表达式中。

谢谢!

I'm trying to figure out a solution for passing all relevant HTTP requests to my index.php bootstrap file.

The two rules I want to enforce are:

  • Any directory,
  • Any file with a .html or .ajax file extension (in any directory).

None of these files or directories actually exist - bootstrap PHP file will dynamically output relevant content.


Here is my current .htaccess file

RewriteEngine on
Options +FollowSymLinks
#RewriteCond %{REQUEST_URI}$1 !-f
RewriteRule ^/?(.+(?:\.html?)?)$ index.php [L]
RewriteRule \.ajax$ index.php [L]

The RewriteCond has been commented out as it didn't seem to have any effect, and with the correct RewriteRule it will be made obsolete anyway (image files, javascript files, etc. will not be matched by the rule so don't need to be checked for existance).

I think a regex expert could easily solve this, a plus would also be to combine the two rules into one regex.

Thanks!

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

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

发布评论

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

评论(1

葬﹪忆之殇 2024-10-14 21:47:55

这条规则应该做到这一点:

RewriteRule .+\.(html|ajax)$ index.php

This rule should do it:

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