How do I create a 301 Redirect?

|

301 Redirects can be created in most web server software. The process to create 301 redirects differs for each web server.

Configuring 301 Redirects in Apache

Configuring 301 Redirects in Apache is a two step process, configuring httpd.conf and creating .htaccess.

Configuring httpd.conf to Enable a 301 Redirect

The first step is to edit your httpd.conf file to allow 301 Redirects.

This is done with Apache's Allow Override directive.

Find the line in your httpd.conf file which contains the AllowOverride directive.

Edit this line by adding the "All" option to the end.

Example:

AllowOverride All

Save the file and restart Apache to make the configuration change take effect.

Creating a .htaccess File to Configure a 301 Redirect

The next step is to actually create your .htaccess file.

The .htaccess file should be in the DocumentRoot directory for your web site.

The .htaccess file contains two columns. The first column is what you want redirected and the second column is where you want it redirected to.

For example, to redirect an entire web site to another site:

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

Or, to redirect just one page to another page:

Redirect 301 /old-page.shtml http://www.example.com/new-page.shtml

Other Redirects

There are redirects other than 301, although they are less frequently utilized.

Redirect types are defined in RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1.

Other redirect types include:

Numeric CodeNameMeaning
301PermanentThe resource has permanently moved
302TempThe resource has temporarily moved
303SeeotherThe resource has been replaced

Configuring 301 Redirects in Microsoft Internet Information Server (IIS)

Instructions for creating a 301 redirect in Microsoft IIS are available at Microsoft Knowledge Base Article 313074 - HOW TO: Redirect Browser Requests in Internet Information Services 5.0.

If you do not have Administrative access to the IIS server, you can still create a 301 Redirect by following the instructions at ASP Tips - 301 Moved Permanently - Redirecting URLs with ASP.

0 comments:

Post a Comment