从htaccess的重写规则排除文件 [英] Excluding files from htaccess rewrite rules

查看:328
本文介绍了从htaccess的重写规则排除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在通过引导程序文件,我的PHP应用程序路径文件一个htaccess重写设置。从本质上说,我们的目标是采取一个URL如www.domain.com/view/key/value/key/value其中该视图将相应地路由和键/值对将可经由一个函数I在引导程序写的意见。一切运作良好...

I have an htaccess rewrite setup in my PHP application to route files via the bootstrapper file. In essence, the goal is to take a URL such as www.domain.com/view/key/value/key/value where the view would route accordingly and the key/value pairs would be available via a function I wrote in the bootstrapper to the views. All was working well...

也就是说,直到我开始做AJAX-Y的东西。我通过一个单一的文件,ajaxDispatcher.php路由我所有的Ajax查询。当我这样做,htaccess的(正确)抓住了请求,并用我的引导程序来路由它不恰当。同样,它试图航线不需要的文件,如.ICO,的CSS等。

That is, until I started doing ajax-y stuff. I'm routing all my ajax queries through a single file, ajaxDispatcher.php. When I did that, the htaccess (correctly) caught the request and used my bootstrapper to route it inappropriately. Similarly, it was attempting to route unwanted files such as .ico, .css, etc.

我想通了,文件扩展名路由异常,但是,我已经无法拥有的.htaccess忽略重写规则的单个文件ajaxDispatcher.php。这里就是我的code代表:

I figured out the file extension routing exception, however, I've not been able to have .htaccess ignore rewrite rules for the single file ajaxDispatcher.php. Here's where my code stands:

 RewriteEngine On
 RewriteBase /
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^/ajaxDispatcher.php$ $0 [L]
 RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php?route=$1 [L]

我如何得到的.htaccess忽略路由规则仅适用于ajaxDispatcher?

How do I get .htaccess to ignore the routing rules only for ajaxDispatcher?

推荐答案

您应该将你的新规则之上的RewriteCond块:

You should move your new rule atop the RewriteCond block:

RewriteRule ^/?ajaxDispatcher.php$ - [L]

否则RewriteConditions不包括扩展重写规则了,为此,我认为,他们的目的。

Otherwise the RewriteConditions don't cover the extensions RewriteRule anymore, for which I assume they are intended.

另一种方法是将其转化过程中的另一个的RewriteCond:

Another alternative is turning it into another RewriteCond of course:

RewriteCond %{SCRIPT_NAME}  !ajaxDispatcher

或注射作为断言进入最后重写规则(?!ajaxDispatcher.php)

该排序的事情是最好的Serverfault解释:<一href="http://serverfault.com/questions/214512/everything-you-ever-wanted-to-know-about-mod-rewrite-rules-but-were-afraid-to-as">http://serverfault.com/questions/214512/everything-you-ever-wanted-to-know-about-mod-rewrite-rules-but-were-afraid-to-as

The ordering thing is best explained on Serverfault: http://serverfault.com/questions/214512/everything-you-ever-wanted-to-know-about-mod-rewrite-rules-but-were-afraid-to-as

这篇关于从htaccess的重写规则排除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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