ajax page navigation not working after htaccess re

2019-09-09 02:47发布

i use .htaccess to rewrite my url from

/list.php?pat=free&mainCol=maincate&subCol=shoes

to

/maincate/shoes

after rewrite, the ajax next page button is not working anymore. it should load list_pull.php from same folder as list.php

    $.post("list_pull.php",{
        pageCurrent:pageClick,      
        pullSubCol:$("#pullSubCol").val()});

and the htaccess is like this

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

i tried use full path http://www.mydomain.com/list_pull.php - not working i tried creating a folder "maincate" and put listpull.php inside, still not working.

by the way, i have another file same as listpull.php, and it works! the rewrite is like this

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

dont know if my question is clear enough, been trying to figure it out for 2 days now, still no luck.

thanks in advance for help!!

2条回答
再贱就再见
2楼-- · 2019-09-09 03:09

You have redirected all the params after domain name to mainlist.php and the uri string with two / to list.php so i suggest you to add another specific rewrite rule for list_pull.php and replace [L] with [QSA]

QSA means that if there's a query string passed with the original URL, it will be appended to the rewrite (olle?p=1 will be rewritten as index.php?url=olle&p=1.

L means if the rule matches, don't process any more RewriteRules below this one.

RewriteRule ^call_ajax$ /list_pull.php  [QSA]

Now in your ajax call put url like this

$.post("/call_ajax",{
        pageCurrent:pageClick,      
        pullSubCol:$("#pullSubCol").val()
});

Edit Try htaccess.madewithlove.be to test your rewrite rules below i have attached some test rewrites which works fine for me

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

enter image description here

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

enter image description here

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

enter image description here

查看更多
孤傲高冷的网名
3楼-- · 2019-09-09 03:17

Just add RewriteCond %{REQUEST_FILENAME} !-f before RewriteRule

查看更多
登录 后发表回答