Thursday, 17 October 2013

Difference between rewrite and redirect

The main difference between rewriting and redirecting is,  Redirecting sends a HTTP 301 or 302 to the client, telling the client that it should try to access the page using another URL. This means that the client knows that there is another URL that should be used. The communication between the server and client is like:

Request 1 (from client):     Get index.php
Response 1 (from server).  The file is moved, please request the file temp_index.php
Request 2 (from client):     Get temp_index.php
Response 2 (from server):  Here is the content of temp_index.php

Rewriting happens on the server, and simply is a translation of one URL to another, that is used by your web application. The client does not know that internally there is another URL, it just sees the one it sent to the server.

Request 1 (from client):       Get  index.php
URL Rewriting (on server):   Translate the URL  index.php  to temp_index.php
Web application (on server): Process the request (run any code in temp_index.php)
Response 1 (from server):    Here is the content of index.php (note that the client does not know that this is the content of temp_index.php)

No comments:

Post a Comment