Question

Is there a way for a web server to issue a redirect that does not require the browser to issue a second request?

For example, the browser requested http://www.mysite.com/lion, but the server wants the browser to change location to http://www.mysite.com/jungle. The only way I know how to accomplish this is for the server to send a 3xx status code with the jungle URL, and the browser issues a new request to retrieve it.

Is it possible for the server to deliver the page jungle in response to the lion request, and just tell the browser "Set your URL to http://www.mysite.com/jungle"?

Was it helpful?

Solution

Yes, it's called URL rewriting. Both Apache and IIS have modules that allow this.

For Apache, in a .htaccess file or your httpd.conf within a virtual host:

RewriteEngine On
RewriteRule lion jungle [L]

The contents of jungle will be sent when lion is requested, without a redirect.

OTHER TIPS

In ASP.NET, you can use Server.Transfer(). This causes a different page to be returned for the current request.

Note that the browser has no knowledge this is happening. It would still show http://www.mysite.com/lion in the address bar even though you would see the content from http://www.mysite.com/jungle.

If you want to inform the browser that a different page is being loaded, then you need a redirect as far as I'm concerned.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top