What is a 301 redirect?
A 301 redirect is a permanent forwarding/redirect of a URL. When you retire addresses and move their content to a new address — for example during a site migration — it is extremely important from an SEO perspective that you set up correct 301 redirects.
This is how you inform search engines that the content at a given address has moved to a new address.
In this way, you avoid having to "start from scratch" at the new address, as the accumulated value of the old address will be passed on to the address being 301-redirected to.
How do you create a 301 redirect?
The vast majority of modern CMS systems have built-in functionality for creating 301 redirects. Alternatively, in many cases you can find a module/plugin to help you set up 301 redirects.
If your system does not have built-in 301 redirect handling or the option to install a plugin/module for it, it depends on whether your website is hosted on a PHP server or an ASP.NET server.
Here is how you create 301 redirects on the two different server types:
How to create 301 redirects on a PHP server
If your site is hosted on a PHP server, you create 301 redirects through the .htaccess file in the root of your web hosting account.
If you do not already have one, you can simply create one and place it in the root of your web hosting account, or alternatively edit the one you already have.
In the example below, we assume that a redirect needs to be created from the address https://eksempel.dk/adresse1 to https://eksempel.dk/adresse2. If "RewriteEngine on" is already present in your .htaccess file, the following should be inserted into your .htaccess file:
Redirect 301 /adresse1 https://eksempel.dk/adresse2
Alternatively, "RewriteEngine on" should be written above your redirects in the .htaccess file. Below that, you can then place all your redirects.
How to create 301 redirects on an ASP.NET server
If your website is hosted on an ASP.NET server, redirects are set up through the web.config file, which is also located in the root of your web hosting account.
To create a 301 redirect in your web.config file, you first need to scroll down and find the </handler> line under <system.webServer>. After </handler>, the following code snippet should be inserted.
Again, we assume that a 301 redirect needs to be created from the address https://eksempel.dk/adresse1 to https://eksempel.dk/adresse2.
- <rewrite>
- <rules>
- <rule name="redirect1" stopProcessing="true">>
- <match url="(.*)" />
- <conditions logicalGrouping="MatchAny" trackAllCaptures="false">>
- <add input="{HTTP_HOST}{REQUEST_URI}" pattern="eksempel.dk/adresse1" />
- <add input="{HTTP_HOST}{REQUEST_URI}" pattern="www.eksempel.dk/adresse1" />
- </conditions>
- <action type="Redirect" url="https://eksempel.dk/adresse2" redirectType="Permanent">/>
- </rule>
- </rules>
- </rewrite>
We will always recommend, where possible, that you create your 301 redirects through the system you are using.
Read our guide to 301 redirects and SEO here
Do you need help setting up correct 301 redirects and ensuring that your website's SEO value is preserved when making changes? We can help you ensure that your URL redirects work optimally. Fill in the form below or call us on 30 12 42 72 for a no-obligation chat!