Hello I'm having great difficulty making it so .htaccess will stop rewriting the url in a ajax call..
你好,我很难做到这一点.htaccess将停止在ajax调用中重写url ..
my .htaccess below:
我的.htaccess如下:
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{HTTP:X-Requested-With} !=XMLHttpRequest
RewriteRule ^([^/\.]+)/?$ index.php?system=$1
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?system=$1&task=$2
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?system=$1&task=$2&id=$3
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?system=$1&task=$2&id=$3&data=$4&key=$5
and the PHP ajax call:
和PHP ajax调用:
<script>
$(document).ready(function () {
$(".checkButton").click(function () {
var objID = this.id;
$.ajax({
url: "/update.php",
type: 'POST',
data: {val: objID},
success: function (data, textStatus, jqXHR)
{
alert("sucess" + data);
},
error: function (jqXHR, textStatus, errorThrown)
{
alert(textStatus + errorThrown + jqXHR);
}
});
});
});
Because of an existing large amount of code I don't want to change the rewrite rules we have in place already but find a way in which I can ignore the rewrite rules for only a ajax request. I have been searching around for a while and I only managed to find suggestions of using
由于存在大量代码,我不想更改已经存在的重写规则,但是我找到了一种方法,可以忽略只有ajax请求的重写规则。我一直在寻找一段时间,我只是设法找到使用的建议
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{HTTP:X-Requested-With} !=XMLHttpRequest
edit:
编辑:
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP:X-Requested-With} !=XMLHttpRequest
RewriteRule ^([^/\.]+)/?$ index.php?system=$1
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?system=$1&task=$2
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?system=$1&task=$2&id=$3
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?system=$1&task=$2&id=$3&data=$4&key=$5
Revised .htaccess ajax is still unable to find the page after testing.
修改后的.htaccess ajax仍然无法在测试后找到该页面。
1 个解决方案
#1
2
RewriteCond
works just for the first RewriteRule
just after.
RewriteCond仅适用于第一个RewriteRule。
Use instead:
改为使用:
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{HTTP:X-Requested-With} =XMLHttpRequest
RewriteRule ^ - [L]
RewriteRule ^([^/.]+)/?$ index.php?system=$1 [L]
RewriteRule ^([^/.]+)/([^/.]+)/?$ index.php?system=$1&task=$2 [L]
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ index.php?system=$1&task=$2&id=$3 [L]
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/?$ index.php?system=$1&task=$2&id=$3&data=$4&key=$5 [L]
#1
2
RewriteCond
works just for the first RewriteRule
just after.
RewriteCond仅适用于第一个RewriteRule。
Use instead:
改为使用:
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{HTTP:X-Requested-With} =XMLHttpRequest
RewriteRule ^ - [L]
RewriteRule ^([^/.]+)/?$ index.php?system=$1 [L]
RewriteRule ^([^/.]+)/([^/.]+)/?$ index.php?system=$1&task=$2 [L]
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ index.php?system=$1&task=$2&id=$3 [L]
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/?$ index.php?system=$1&task=$2&id=$3&data=$4&key=$5 [L]