htaccess 301 (permanent) Redirect and RedirectMatch

There are many different types of redirects. Here are a few different permanent redirects. All of these can be added to your htaccess file. The directories listed are relative to the htaccess location.

Redirect visitors of a single page to a different page.

# Redirect permanent /directory/index.html http://subdomain.domain.tld/AnotherPage.html

Redirect visitors of any page within a directory to a specific page.

# RedirectMatch 301 ^/mydirectory/ http://subdomain.domain.tld/AnotherPage.html

Redirect visitors of any page within a directory to that page in a different location. Notice the missing slash here, compared to above.

# RedirectMatch 301 ^/mydirectory http://subdomain.domain.tld/AnotherPage.html

Redirect your entire website to any other domain or directory

# Redirect 301 / http://domain.tld/

301 (Permanent) Redirect: Point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the “my-example.com” domain:

# This allows you to redirect your entire website to any other domain
Redirect 301 / http://my-example.com/

302 (Temporary) Redirect: Point an entire site to a different temporary URL. This is useful for SEO purposes when you have a temporary landing page and plan to switch back to your main landing page at a later date:

# This allows you to redirect your entire website to any other domain
Redirect 302 / http://my-example.com/

Redirect index.html to a specific subfolder:

# This allows you to redirect index.html to a specific subfolder
Redirect /index.html http://example.com/newdirectory/

Redirect an old file to a new file path:

# Redirect old file path to new file path
Redirect /olddirectory/oldfile.html http://example.com/newdirectory/newfile.html

Redirect to a specific index page:

# Provide Specific Index Page (Set the default handler)
DirectoryIndex index.html

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Please enter 10 numbers for Captcha: * Time limit is exhausted. Please reload the CAPTCHA.