RewriteRule 中的正则表达式,传递给引导 PHP 文件
我正在尝试找出一种解决方案,将所有相关的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这条规则应该做到这一点:
This rule should do it: