Skip to main content

How do I make a 301 redirect

If you want to redirect a URL to another one, you want want to create a redirect, this is typically done using the 301 status code (if this is just a short term redirect you'll want the 302 status code).

This is how we'd do it in several of the most popular web hosting technologies.

Apache

For a simple redirect, you can edit your .htaccess file

    Redirect 301 /oldpage.html /newpage.html

However if you want to do folder base rules or redirect a whole website then you can use the RewriteEngine

    RewriteEngine On
RewriteRule ^oldpage\.html$ /newpage.html [R=301,L]

(Obviously this module will need to be enabled on your server but it usually is).

NGINX

For NGINX we want to take a look at the server block usually in /sites-available

    server {
server_name example.com;
location /oldpage {
return 301 $scheme://example.com/newpage;
}
}

Microsoft IIS

For IIS We can look at the IIS Manager GUI but if you WANT to edit some files then look at the web.config file

    <configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect old page to new page" stopProcessing="true">
<match url="^oldpage.html$" />
<action type="Redirect" url="/newpage.html" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

After you've changed it

Remember to restart your web server and head over to Little Warden to check that it's responding correctly!