类似Nginx的try_files阿帕奇重写规则 [英] Apache rewrite rule similar to Nginx try_files

查看:505
本文介绍了类似Nginx的try_files阿帕奇重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Nginx的我打得四处try_files基本上采取任何请求域上的文件,并通过它通过一个名为file_parse.php定制的PHP脚本。在Nginx的它看起来是这样的:tr​​y_files $网址/file_parse.php

In Nginx I played around with try_files which basically took any request for a file on the domain and passed it through a custom php script called file_parse.php. In Nginx it looked like this: try_files $url /file_parse.php

如果该文件没有在文档根存在,那么它并没有使用try_files。此规则在Nginx的不重定向用户,例如,如果在 HTTP用户类型://www.domain .COM / 123456.html 该地址显示在他们的浏览器,但根据编号(123456)file_parse.php需要123456.html和回声的HTML出code。如果file_parse.php并没有什么呼应了那么file_parse.php用于设置客户端一个404头。

If the file did exist in the document root then it did not use try_files. This rule in Nginx doesn't redirect the user, for example if a user types in http://www.domain.com/123456.html that address shows in their browser but file_parse.php takes 123456.html and echo's out html code based on the number (123456). If file_parse.php doesn't have anything to echo out then file_parse.php sets a 404 header for the client.

请问这样的事情存在于Apache的?

Does something like this exist in Apache?

推荐答案

找到了答案,似乎工作,在error.log中没有任何错误:

Found an answer, seems to work, no errors in error.log:

<Directory /this/is/the/directory/>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . file_parse.php [L]
</Directory>

这篇关于类似Nginx的try_files阿帕奇重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆