Sacado de http://library.linode.com/web-servers/apache/configuration/redirecting-urls
Gracias al plug
Redirect URLs with the Apache Web Server
When HTTP resources, or web pages, change locations it is often important to provide some means of alerting users that these resources have moved. HTTP provides a number of "redirection" codes that can be used to facilitate this process, by communicating with he client application without interfering on the users experience.Apache provides a number of "redirect" configuration directives that allow administrators to specify resources in the configuration file to redirect to another URL. When a request is redirected the server returns a result for that request that instructs the client to initiate a second request for the target resource's new location.
Redirections can tell the client that the requested page has been moved temporarily or permanently. Apache provides tools to easily support these functions. This guide covers the Redirect configuration directive, explains how to set various redirect options, and shows how to redirect classes of requests for resources to new locations.
This guide assumes you have a working installation of Apache and have access to modify configuration files. If you have not installed Apache, you might want to use one of our Apache installation guides or LAMP stack installaiton guides to get up and running first. If you want a more thorough introduction to Apache configuration, consider our basic Apache configuration and Apache configuration structure documents.
The Redirect Directive
The Redirect configuration directive can be located in "main" server configuration files, but we recommend that you keep them in your virtual hosting entry or directory blocks. It is also possible to assert Redirect statements in .httaccess files. Here is an example of a Redirect directive:
File excerpt:Apache configuration option
Redirect /squire http://team.ducklington.org/~squire/
Remember that no matter what configuration file they are located in, Redirect statements must specify the full path of the redirected resource following the domain name. These statements must also include the full URL of the resource's new location..
To specify a particular HTTP redirection status, specify one of the following status:
File excerpt:Apache configuration option
Redirect permanent /squire http://team.ducklington.org/~squire/
Redirect temp /squire http://team.ducklington.org/~squire/
Redirect seeother /squire http://team.ducklington.org/~squire/
Redirect gone /squire
You can also specify specific HTTP codes, as follows.
File excerpt:Apache configuration option
Redirect 301 /squire http://team.ducklington.org/~squire/
Redirect 302 /squire http://team.ducklington.org/~squire/
Redirect 303 /squire http://team.ducklington.org/~squire/
Redirect 410 /squire
File excerpt:Apache configuration option
RedirectPermanent /squire/bio.html http://team.ducklington.org/~squire/bio/
RedirectTemp /squire/bio.html http://team.ducklington.org/~squire/bio/
File excerpt:Apache configuration option
RedirectMatch (.*)\.jpg$ http://static.ducklington.org$1.jpg
- A request for http://www.ducklington.org/avatar.jpg will be redirected to http://static.ducklington.org/avatar.jpg and
- A request for http://www.ducklington.org/images/avatar.jpg will be redirected to http://static.ducklington.org/images/avatar.jpg.
Beyond URL Redirection
The Redirect directive provides basic functionality to point requests for specific resource to different URLs and can help administrators move content to different servers and locations without breaking existing links. However, many Apache users use the facility to "rewrite" URLs in Apache's mod_rewrite module. If you're struggling to keep your Apache configuration organized or need more control than these Redirect statements can provide, we encourage you to investigate mod_rewrite.The Linode Library contains an introduction to rewriting URLs with mod_rewrite and Apache, which you might find useful.
No hay comentarios.:
Publicar un comentario