htaccess重写后ajax页面导航无法正常工作

时间:2013-09-15 15:44:15

标签: php .htaccess mod-rewrite url-rewriting

我使用.htaccess从

重写我的网址
/list.php?pat=free&mainCol=maincate&subCol=shoes

/ maincate /鞋

重写后,ajax下一页按钮不再工作。它应该从list.php

的同一文件夹中加载list_pull.php
    $.post("list_pull.php",{
        pageCurrent:pageClick,      
        pullSubCol:$("#pullSubCol").val()});

和htaccess就是这样的

RewriteRule ^([^/.]+)/([^/.]+)$ /list.php?pat=free&mainCol=$1&subCol=$2  [L]

我尝试使用完整路径http://www.mydomain.com/list_pull.php - 无法正常工作 我尝试创建一个文件夹“maincate”并将listpull.php放入其中,但仍无效。

顺便说一句,我有另一个与listpull.php相同的文件,它有效! 重写就像这样

RewriteRule ^([^/.]+)$ /mainlist.php?pat=free&mainCol=$1  [L]

不知道我的问题是否足够清楚,现在试图解决它2天,仍然没有运气。

提前感谢您的帮助!!

2 个答案:

答案 0 :(得分:1)

您已将域名后的所有参数重定向到mainlist.php,并将uri字符串重定向到两个/list.php,因此我建议您为{{1}添加另一个特定的重写规则用 [QSA]

替换 [L]

list_pull.php表示如果有一个与原始网址一起传递的查询字符串,则会将其附加到重写中(QSA将被重写为olle?p=1

index.php?url=olle&p=1表示如果规则匹配,则不再处理此规则以下的RewriteRules。

L

现在在你的ajax调用中把url放在这样的

RewriteRule ^call_ajax$ /list_pull.php  [QSA]

修改尝试htaccess.madewithlove.be测试您的重写规则,我附上了一些测试重写对我来说很好

1)http://www.example.com/call_ajax RewriteRule ^ call_ajax $ /list_pull.php [QSA]

enter image description here

2)http://www.example.com/call/ajax到RewriteRule ^([^ /。] +)/([^ /。] +)$ / list.php?pat=free&mainCol=$1&subCol= $ 2 [QSA]

enter image description here

3)http://www.example.com/call到RewriteRule ^([^ /。] +)$ / mainlist.php?pat=free&mainCol=$1 [QSA]

enter image description here

答案 1 :(得分:0)

只需在RewriteRule

之前添加RewriteCond %{REQUEST_FILENAME} !-f