apache 从 .htaccess 中的重写规则中排除文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1839537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 18:28:02  来源:igfitidea点击:

exclude files from rewrite rule in .htaccess

apache.htaccessxajax

提问by Cruachan

I'm modifying an existing website that uses a fairly complex .htaccess file to implement a custom MVC type framework so all urls are redirected to index.php?[some parameters] or a 404 page. I'd like to add ajax support to a limited area of the site using XAJAX, and to implement that I need to place two files in the root which are ignored by the rewrite rules. How do I do that?

我正在修改一个现有网站,该网站使用相当复杂的 .htaccess 文件来实现自定义 MVC 类型框架,因此所有 url 都被重定向到 index.php?[某些参数] 或 404 页面。我想使用XAJAX将 ajax 支持添加到站点的有限区域,并且要实现这一点,我需要在根目录中放置两个文件,这些文件被重写规则忽略。我怎么做?

回答by habe

How about identity rewriting rule with “last” flag on the top of your rules?

规则顶部带有“last”标志的身份重写规则怎么样?

For example, to exclude “/a-file-outside-of-rewriting.html” from current set of rules, the following configuration might help:

例如,要从当前规则集中排除“/a-file-outside-of-rewriting.html”,以下配置可能会有所帮助:

# http://~/outside-of-rewriting.html will be rewritten to itself (i.e., unmodified).
# then no more rules will be applied (because it has “last” flag.)
RewriteRule ^/a-file-outside-of-rewriting.html$ ##代码## [L]

RewriteRule ^/any/other/rules(/.*) 
RewriteRule ^/already/exist(/.*) 
# ...