[ Team LiB ] |
Recipe 5.8 Redirecting to Another LocationProblemYou want requests to a particular URL to be redirected to another server. SolutionUse a Redirect directive in httpd.conf, and give an absolute URL on the second argument: Redirect /example http://www.other.server/new/location DiscussionWhereas Alias maps a URL to something in the local filesystem, Redirect maps a URL to another URL, usually on another server. The second argument is a full URL and is sent back to the client (browser), which makes a second request for the new URL. It is also important to know that the Redirect directive preserves path information, if there is any. Therefore, this recipe redirects a request for http://original.server/example/something.html to http://www.other.server/new/location/something.html. Redirections come in several different flavors, too; you can specify which particular type of redirect you want to use by inserting the appropriate keyword between the Redirect directive and the first URL argument. All redirects instruct the client where the requested document is now; the different types of redirection inform where the client should look for the document in the future.
By default, if no keyword is present, a temporary redirection is issued. Here's an example of the various directive formats, including the HTTP status code number in case you want to use an ErrorDocument to customize the server's response text: # # These are equivalent, and return a response with a 302 status. # Redirect /foo.html http://example.com/under-construction/foo.html Redirect temp /foo.html http://example.com/under-construction/foo.html RedirectTemp /foo.html http://example.com/under-construction/foo.html # # These are equivalent to each other as well, returning a 301 status # Redirect permanent /foo.html http://example.com/relocated/foo.html RedirectPermanent /foo.html http://example.com/relocated/foo.html # # This tells the client that the old URL is dead, but the document # content has been replaced by the specified new document. It # returns a 303 status. # Redirect seeother /foo.html http://example.com/relocated/bar.html # # Returns a 410 status, telling the client that the document has been # intentionally removed and won't be coming back. Note that there # is no absoluteURL argument. # Redirect gone /foo.html See Also |
[ Team LiB ] |