If you have long nasty URLs on your site and you wish to shorten them or make them more friendly to users or search engines — one solution can be found using Apache’s mod_alias.

In order to use this solution you will need to have rights to edit Apache’s conf files or just the conf file for your virtual host.

The basic format is:

Redirect <status> <old URL> <new URL>

Status is optional. The default value is 302.

Status Description
301 Permanent This tells the browser and search engine to permanently disregard the old URL and only pay attention to the new URL. Use this when you are permanently moving content off-domain or restructuring your on-domain page tree.
302 Temporary Use temporary redirects when you want to clean up on-domain links. Search engines will continue to index the old URL but browsers will redirect to the new URL. For example use a 302 status to redirect team.league.com to city.team.league.com/display.php?team=123.
303 See other This status code is useful to prevent duplicate form submissions.
401 Gone This is telling the browser that the page is gone forever. In this case do not supply a URL to redirect to.

Examples:
Redirect all requests to a new domain

Redirect 301 / http://www.newdomain.com/

Permanently redirect an on-domain path to a new on-domain path

Redirect 301 /old/foo /new/foo

Temporarily redirect a path off domain. (Search engines will treat this as a 301)

Redirect /foo http://www.offdomain.com/foo

Indicate that the given page is gone forever.

Redirect 401 /dead/page.html

image licensed under creative commons