HTaccess与Ajax脚本冲突

htaccess in conflict with ajax script

本文关键字:冲突 脚本 Ajax HTaccess      更新时间:2023-09-26

我在js中使用pushstate事件,因此重写了我的htaccess,以便将url中的每个路径重定向到索引.php:

# html5 pushstate (history) support:
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.php [L]
</ifModule>

这工作得很好..但是我构建了一个ajax脚本,我可以在其中检查某些图像是否可用。

function loadPicture(selector, file, errorf){
    $.ajax({url: file,type:'HEAD',error:function(){
        $(selector).attr('src', errorf);
        $('#notavailable').show();
    }, success:function(){
        $(selector).attr('src', file);
        if($('#notavailable').is(':visible')){
               $('#notavailable').hide();
        }
    }});
};

这个脚本不再工作了,我意识到这是因为 .htaccess。

现在我真的不是 htaccess 方面的专家,我发现很难理解,并且肯定需要一些帮助。 也许有人可以告诉我如何将每个顶级/根路径(例如 domain.com/somethingtoredirect)重定向到我的索引.php但对某些甚至每个文件夹(domain.com/thisfoldershouldnotberedirectedByHtAccess)例外

我认为这将解决我的问题,因为我正在检查的图像不是存储在高级而是存储在子文件夹中。

任何帮助都非常感谢。

罗马

只需从全部捕获规则中排除图像文件夹:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/dummy-image-folder/ [NC]
RewriteRule ^ index.php [L]