By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

Redirecting pages with htaccess

How to redirect pages with htaccess. This tutorial shows how to do redirects in htaccess.

Edited: 2015-12-04 12:31

This tutorial shows how to Redirect pages with htaccess, in this turotial we deel with two types of redirects. The temporary redirect and the permanent redirect.

It can be important that we redirect pages that has been moved, so that we do not lose visitors. That is where the permanent redirect comes in.

When performing redirects in htaccess, you can either use Redirect, RedirectMatch and you can use mod_rewrite.

Using Redirect

Used when a page is moved permanently, often used when changing domains, or changing the site structure.

Redirect 301 /old-page.html

Redirecting the whole Site:

Redirect 301 /

Note. When wanting to use the Temporary Redirect, simply change 301 to 302.

Redirect 302 /

Using RedirectMatch

If you have changed the file extension of a page, for example to .php from .html, you can use a regular expression to remember the file name, and redirect to the new file extension.

RedirectMatch 301 (.*)\.html$$1.php

Note. The content of the parentheses is remembered, or back-referenced. The . dot allows any character, and the * asterix allows none or more characters to be present.