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

Learn more

301 redirect in htaccess

How to do a 301 redirect with htaccess

Edited: 2015-12-04 12:10

There are a few ways to perform 301 redirects in Htaccess, but before implementing them, you should know that they are best suited for static content.

If your site is using a modern CMS, then you may want to consider doing it from within your CMS rather than the sites .htaccess files. The main reason for this, is that on dynamic websites, where users might change URLs from time to time, you would want an easy way to maintain all of your redirects.

One of the best way to perform redirects from a CMS, is to have a table in the database containing all the changed URLs. You can then easily intercept requests that would otherwise produce a 404 response status code, and check them against the table in the database. If your CMS system does not already do this, there might still be a module for your CMS that enables this functionality.

The below shows how to do a simple 301 redirect in htaccess.

Redirect 301 /old-page.html http://www.brugbart.com/newpage.html

Whole site redirect

If you changed your domain name, you can also redirect your entire site to the new domain. You will however still need to have access to the old domain.

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