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).

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):

This does not work. The ajax request made to the ajax.php is not working. "Page not found" error.
–
Gaurav SharmaMay 12 '11 at 6:46

Perhaps try removing the absolute reference and make it relative (instead of '/ajax.php..', change to just 'ajax.php...') it may fix it and match the way your other rules appear. Have you checked to ensure the ajax.php file exists in the location being referenced as well if the relative change doesn't work?
–
Phil StreetMay 13 '11 at 0:14

here is a workaround/hack that I found while fiddling with the rules. If I specify the rules in some order than it works perfectly. i.e. I added the ajax.php and admin.php rule after the last line in the answer above., and then I moved the index.php?page=$1%{QUERY_STRING} rule below the ajax.php and admin.php rewrite rule. still testing it for any errors.
–
Gaurav SharmaMay 13 '11 at 7:47

Sounds like some progress at least! Hopefully it works out.
–
Phil StreetMay 13 '11 at 14:25

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.

Thanks for your reply. The Last rule created problems that is why I posted my question over here. How can I make all the rules work simultaneously without breaking the ajax and admin requests? I know the task is not impossible.
–
Gaurav SharmaMay 11 '11 at 10:51