Code Snippet: 301 redirects using .htaccess

A 301 redirect is a permanent way to let search engines and visitors know that an old page on your website has been replaced by a new one.

If you would like to create your own redirects using your website’s htaccess, open your .htaccess file (typically found at the root of your website) and add the following code:

Redirect 301 /myveryoldpage.html
Redirect 301 /login/

If you would like to redirect your entire website to a new website and you are keeping the exact same page structure you can add the following code to your old website:

Redirect 301 /

As an example, the code above will cause to redirect to so there is no need to worry about creating a separate redirection for each page.

One thing to note is that .htaccess redirections only work on Apache servers.