从影响AJAX请求文件prevent的htaccess文件、AJAX、htaccess、prevent

2023-09-02 01:14:19 作者:夏末初秋

我在的.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]
 
精彩推荐
图片推荐