从影响AJAX请求文件prevent的htaccess [英] Prevent htaccess from affecting ajax file requests

查看:244
本文介绍了从影响AJAX请求文件prevent的htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在的.htaccess 文件清理一些网址重写规则,我还需要在我的网页AJAX调用。我有问题,因为重写规则的AJAX文件请求。这是我的htaccess文件的内容:

I have some rewrite rules in my .htaccess file for clean URLs, and I also need AJAX calls in my web pages. I have problems with ajax file requests because of the rewrite rules. Here is my htaccess file content:

Options -MultiViews
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteBase /~mavili/loran/orders/
RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]

当我做这样的事情:

$.ajax({
    type: 'get',
    url: 'http://domain.com/misc/page.php',
    success: function(data) {
        $('#load_content').html(data);
    },
    error: function() {
       $('#load_content').html('Error: Unable to load file.');
    }
});

http://domain.com/misc/page.php 的请求经过htaccess的重写规则,搅乱一切。有没有什么办法prevent从经历htaccess的设置?

the request for http://domain.com/misc/page.php goes through the htaccess rewrite rules and messes everything. Is there any way to prevent AJAX calls from going through htaccess settings?

推荐答案

使Ajax请求跳过规则仍坚持在URL如虚设查询参数的一种方法这样的:

One way of making Ajax request skip the rules is sticking a dummy query parameter in the URL e.g. this:

$.ajax({
    type: 'get',
    url: 'http://domain.com/misc/page.php&skip=1',
    success: function(data) {
        $('#load_content').html(data);
    },
    error: function() {
       $('#load_content').html('Error: Unable to load file.');
    }
});

和有你重写规则这样跳过与所有的请求跳过= 1 查询参数:?

And have your rewrite rules like this to skip all requests with ?skip=1 query parameter:

Options -MultiViews
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteCond %{QUERY_STRING} !^skip=1$
RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]

这篇关于从影响AJAX请求文件prevent的htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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