【问题标题】:htaccess in conflict with ajax scripthtaccess 与 ajax 脚本冲突
【发布时间】:2013-09-17 01:54:33
【问题描述】:

我在 js 中使用 pushstate 事件,因此重写了我的 htaccess,以便将我的 url 中的每个路径重定向到 index.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 )重定向到我的 index.php 但对某些甚至每个文件夹( domain.com/thisfoldershouldnotberedirectedByHtAccess )进行例外处理

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

非常感谢任何帮助。

罗马

【问题讨论】:

    标签: javascript html ajax .htaccess conflict


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-09
      • 1970-01-01
      • 1970-01-01
      • 2021-07-02
      • 1970-01-01
      • 1970-01-01
      • 2014-11-15
      • 1970-01-01
      相关资源
      最近更新 更多