snew
snew

Reputation: 101

jQuery ajax + htaccess

I have wildcard dns on the server and dynamic subdomains working properly on the server. However there is a problem with the Ajax file processing through jQuery.

Below is the jQuery Ajax code:

$.ajax({
    type: 'GET',
    url: 'process.php',
    data: 'grpid=' + group_select.val(),
    success: function(data)
    {
      $('#grpsrv').html(data);            
      $('#spinner').css('display','none');
    }
});

So internally file will be processed as for example process.php?grpid=88.

In the .htaccess file the line is written as follows:

RewriteRule ^process.php?([A-Za-z0-9]+)$ /home/server-path/user-website/process.php?grpid=$1

But when I echo the $_GET['grpid'] on process.php it is showing blank value.

How to write a RewriteRule for Ajax file?

Upvotes: 0

Views: 2880

Answers (2)

Powerlord
Powerlord

Reputation: 88796

I would advise you to just let mod_rewrite handle it using the RewriteRule [QSA] flag

RewriteRule ^process.php$ /home/server-path/user-website/process.php [QSA]

[QSA] tells Apache to copy the original request's query string to the new url's query string.

Upvotes: 1

rfunduk
rfunduk

Reputation: 30432

Well it looks like your first regex is not working correctly. It will probably match your group id, but not grpid=someid. Try:

RewriteRule ^process.php?grpid=([A-Za-z0-9]+)$ /home/server-path/user-website/process.php?grpid=$1

Also, you might want to enable rewrite logging to see if your rule is getting triggered correctly in the first place, and watch the error logs, too.

Upvotes: 1

Related Questions