开发者

Ajax and admin requests stopped functioning by entering mod-rewrite rules

I am new to url-rewriting.

I have written few rewrite rules in the .htaccess file. My problem is that the ajax request and the admin section (both of which are being managed by different files, named ajax.php and admin.php) not working at all.

Here is what I am trying to achieve using mod-rewrite :

The URL : http://websitename/index.php?page=rr&cn=abc&cid=1

should look like this : http://websitename/rr/abc/1

in the addressbar of browser

and

The URL (having only 'page' value): http://websitename/index.php?page=register

should look like this : http://websitename/register

in the addressbar of browser

and

The URL : http://websitename/index.php?page=i&in=banking&iid=12

should look like this : http://websitename/industry/banking/12

in the addressbar of browser

and

The URL : http://websitename/index.php?page=cr&cn=pqr&rid=12

should look like this : http://websitename/cr/pqr/12

in the addressbar of browser

So far I am able to do this using the following rules but the request made to ajax.php and admin.php along with some parameters are not working at all (page not found error).

Options +FollowSymLinks
RewriteEngine on

RewriteRule ^([A-Za-z0-9-]+)/([^/]+)/([^/]+)$ index.php?page=$1&companyname=$2&companyid=$3%{QUERY_STRING} [L,QSA]

RewriteRule ^([^/]+)$ index.php?page=$1%{QUERY_STRING} [L,QSA]

RewriteRule ^view/([^/]+)/([^/]+)/([^/]+)$ index.php?page=$1&industryname=$2&industryid=$3%{QUERY_STRING} [L,QSA]

RewriteRule ^([^/]*)/([^/]*)/review/([^/]*)$ /index.php?page=$1&companyname=$2&reviewid=$3 [L]

All the three mod-rewrite rules work fine but the ajax requests that is done through a separate file named "ajax.php" are not working (page not found error comes)

i.e. the following URLs should work with above mod-rewrite rules

http://websitename/ajax.php?action=vote

and

http://websitename/admin.php?page=home

(don't want to have mod-rewrite 开发者_开发问答rules for the files ajax.php and admin.php)

But I am not able to successfully do it for ajax.php and admin.php

Please help me on this. I am really stuck on this.

Thanks


From the looks of it, it appears to me your second rewrite rule would be catching both of the URL's you don't want to have rewritten.

RewriteRule ^([^/]+)$ index.php?page=$1%{QUERY_STRING} [L,QSA]

Both these URL's would be picked up in the above rewrite rule

  • http://websitename/ajax.php?action=vote
  • http://websitename/admin.php?page=home

I suggest changing your htaccess to the following, all it's trying to do is catch the admin.php, or ajax.php calls and send them straight through unchanged (I haven't checked this but it should be ok):

Options +FollowSymLinks
RewriteEngine on

RewriteRule ^/ajax.php(.*)$ /ajax.php$1 [L,QSA]
RewriteRule ^/admin.php(.*)$ /admin.php$1 [L,QSA]

RewriteRule ^([A-Za-z0-9-]+)/([^/]+)/([^/]+)$ index.php?page=$1&companyname=$2&companyid=$3%{QUERY_STRING} [L,QSA]

RewriteRule ^([^/]+)$ index.php?page=$1%{QUERY_STRING} [L,QSA]

RewriteRule ^view/([^/]+)/([^/]+)/([^/]+)$ index.php?page=$1&industryname=$2&industryid=$3%{QUERY_STRING} [L,QSA]

RewriteRule ^([^/]*)/([^/]*)/review/([^/]*)$ /index.php?page=$1&companyname=$2&reviewid=$3 [L]


An offhand guess, maybe the ajax.php and admin.php get assimilated into rules 2 or 4 because of the leading '/'. I'm a bit hazy on the exact workings of mod_rewrite, but it might have something to do with it.

Try add rule by rule and test the admin.php and ajax.php pages to figure out which rules are making those pages fail.


Prefix every RewriteRule with the following:

RewriteCond %{REQUEST_FILENAME} !-s

With it your rules will work only when they reference an inexistent file. Requests for exiting files particularly ajax.php and admin.php will be left verbatim.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜