Skip to main content

.htaccess Redirects

.htaccess Redirects

You may need to notify users that a resource has been moved, temporarily or permanently.

To do this, we can use Redirect and RedirectMatch.

Some Examples
<IfModule mod_alias.c>
# Redirect to a URL on a different host
Redirect "/service" "http://foo2.example.com/service"

# Redirect to a URL on the same host
Redirect "/one" "/two"

# Equivalent redirect to URL on the same host
Redirect temp "/one" "/two"

# Permanent redirect to a URL on the same host
Redirect permanent "/three" "/four"

# Redirect to an external URL
# Using regular expressions and RedirectMatch
RedirectMatch "^/oldfile\.html/?$" "http://example.com/newfile.php"
</IfModule>

If RedirectMatch is used, the possible values for the first parameter are listed below.

ValueDescription
permanentReturns a permanent redirect status (301) indicating that the resource has moved permanently.
tempReturns a temporary redirect status (302). This is the default.
seeotherReturns a "See Other" status (303) indicating that the resource has been replaced.
goneReturns a "Gone" status (410) indicating that the resource has been permanently removed. When this status is used the URL argument should be omitted.
note

If the first parameter is not included, the default temp value is used.

Table of Contents