Apache 重写规则类似于 Nginx try_files

Bla*_*ake 5 apache

在 Nginx 中,我使用了 try_files,它基本上接受域上文件的任何请求,并通过一个名为 file_parse.php 的自定义 php 脚本传递它。在 Nginx 中它看起来像这样: try_files $url /file_parse.php

如果该文件确实存在于文档根目录中,则它不使用 try_files。Nginx 中的这条规则不会重定向用户,例如,如果用户输入http://www.domain.com/123456.html该地址显示在他们的浏览器中,但 file_parse.php 需要 123456.html 并回显出 html 代码基于数字 (123456)。如果 file_parse.php 没有任何要回显的内容,那么 file_parse.php 会为客户端设置一个 404 标头。

Apache中是否存在这样的东西?

Bla*_*ake 5

找到了答案,似乎有效,error.log 中没有错误:

<Directory /this/is/the/directory/>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . file_parse.php [L]
</Directory>
Run Code Online (Sandbox Code Playgroud)


Jon*_*Lin 0

Apache 中是否存在这样的东西?

查看 mod_rewrite 的RewriteMap指令,特别是prg允许您运行脚本并向其传递请求信息的映射类型。