Rewritten URL and AJAX

I wonder if it is possible to make work ajax with rewritten urls. For instance I have a php file named receiving a post method call from a javascript :"ajaxfile.php" and has been rewritten to "/rewritten-url/".

Here is the javascript:

$(document).ready(function(){
    $("#button").click(function(){
         $.post("/rewritten-url/", {parameter: "75"}, function(result){
            $("#canvas").html(result);
         });
     });
 });

There is a way to keep the call towards "/rewritten-url/" or have I to keep the call to "ajaxfile.php"? I tried a small example and it works fine with "ajaxfile.php" but not with "/rewritten-url/".

If you ask me "why would I like to do this?" It is just curiosity.

Upvotes: 0

Views: 89

Answers (1)

Polyana Fontes
Polyana Fontes

Reputation: 3216

Yes, you can, ajax requests are the same as normal browser requests, they transfer over http so you can rewrite, redirect, etc.

If you are using apache, you can use the mod_rewrite to do this just like you would do with a normal php file.

Upvotes: 1

Related Questions