How to Implement 301 Redirects in Apache and IIS 7
written by: John Garger•edited by: Rebecca Scudder•updated: 5/19/2011
With both Apache and IIS, you can implement a 301 redirect to avoid losing your page rank in Google and other search engines. Learn how to implement permanent redirection of web pages, directories, and domains to new locations on the Web using Apache Web Server and IIS 7.
This is a problem because the search engines may interpret meta refreshes as an attempt to rank high on a Search Engine Results Page (SERP) for false content but show the real content to users when a visitor requests to view a web page. This happens because the bots that crawl the web in search of content to index in the search engines cannot determine whether the content the user is referred to is really the content indexed in the search engine. This is also a problem for legitimate uses of a meta refresh when the content of a page is located elsewhere and the web administrator just wants the search engines to index the same content that has been permanently moved.
To do a 301 Permanent Redirect in Apache you must have access to the .htaccess file located in the root directory of your web site. Keep in mind that many FTP programs hide such files. You don’t want to write over the web site’s current .htaccess files which may contain important information about your domain, web site, and web pages. In fact, editing of the .htaccess files should really only be attempted by an experienced web administrator. Otherwise follow these steps:
1) Log into your web site using your preferred program and locate the .htaccess file that is normally located in the root web folder. If no .htaccess file is present, you may need to create one but heed the warning about hidden files and FTP programs.
2) Open the .htaccess file in your text editor of choice and add any of the following lines to the file depending on whether you want to permanently redirect a web page or if you want to redirect an entire domain:
To Permanently Redirect a webpage using a 301 Redirect in Apache Web Server, add either of the following lines to the .htaccess files:
To Permanently Redirect an entire domain using a 301 Redirect in Apache Web Server, add the following line to the .htaccess files:
RedirectPermanent / http://www.yournewdomain.com/
Notice that it is not necessary to specify the old domain in the previous domain redirect example. Google, Yahoo, and Bing will already know that information because the .htaccess file’s location tells the search engines from where to redirect the web page or domain.
3) Save the file, upload it to the root directory of your web site, and test that the 301 Permanent Redirect is behaving as you intended.
slide 3 of 4
301 Redirects Using Microsoft Internet Information Services 7.0
Just as with the permanent redirect with Apache above, you can accomplish the same 301 Permanent Redirect if your domain is hosted using IIS 7. To implement a 301 Permanent Redirect using IIS 7.0, follow these steps (of course, you will need administrative access to the server that is running IIS 7 to do this):
1) Click on START>PROGRAMS>ADMINISTRATIVE TOOLS>INTERNET INFORMATION SERVICES (IIS) MANAGER to open the Internet Services Manager.
2) On the left side of the window, select the web page, directory, or entire site that will be the source of the 301 Permanent Redirect (the web page, directory, or site you will be redirecting from).
3) In the Internet Service Manage window, use the FEATURES VIEW to click on the HTTP REDIRECT button.
4) Check the box next to REDIRECT REQUESTS TO THIS DESTINATION and simply type in the address to where you want the 301 Permanent Redirect to go.
For a Web Page, type in: www.yourdomain.com/newwebpagefile.htm
For an entire directory, type in: www.yourdomain.com/newwebdirectory
For an entire domain, type in: www.yournewdomain.com/
5) Under the Redirect Options section, consider the following choices if you have kept your directories and web pages the same (i.e. no directory restructuring and no changes to file names):
REDIRECT ALL REQUESTS TO EXACT DESTINATION: Check this option only if you want every file within the directory to be redirected to a single page.
ONLY REDIRECT REQUESTS TO CONTENT IN THIS DIRECTORY: Check this option if you want to permanently redirect the directory you have chosen but don’t want to redirect any sub-directories within it.
6) Again, as with the Apache 301 Permanent Redirect directions above, test that the 301 Permanent Redirect is behaving as you intended.
slide 4 of 4
301 Permanent Redirects are relatively simple to accomplish if you have administrative access to the server on which Apache or IIS 7.0 is running. 301 Permanent Redirects are much better than Meta Refreshes because they are viewed by the Google, Yahoo, and Bing as “white hat" procedures for moving content from one web site or web site location to another. The procedures discussed in this article will typically not cause your website to rank lower on the Search Engine Results Pages (SERP) due to a suspected devious attempt to rank well in the search engines with one content while showing other content to actual visitors to your web site.