Redirect a URL

There are several reasons to redirect a URL and a few basic ways to approach it. For a website that already has a lot of traffic and good search engine results but needs to change domain addresses, a redirect is a good choice for the transition period. Your traffic still goes to the old domain but is then automatically redirected to the new one. In time, as search engines update their databases, the new domain will pick up its own search results. A redirect can also cause several different URLs to be directed to a single website and can shorten complex URL addresses. Methods for how to redirect a URL depend on what code your website is written in and on how much confidence and experience you have with editing that code.

Steps

Coding an .htaccess 301 Redirect

  1. Find out if your website is running on an Apache server. This is necessary for moving forward with the .htaccess method - check with your web host if you’re unsure.
  2. Locate and download your .htaccess file. An .htaccess file is a file that web servers check for information on how to handle errors, security, and redirect requests for your site. Check your root directory (where all your website files are stored) and then download the file for editing.
  3. Create an .htaccess file. If no .htaccess exists in your root folder currently, you can create one using an application like Notepad (or a similar plain text application). The code for the file is contained in the next step.
    • Make sure that when you save your .htaccess file it begins with a “.”
    • Note that this file has no tail extension (e.g. “.com” or “.txt”)
  4. Type in the code. Paste the following code into the .htaccess text file: .redirect 301 /old/oldURL.com http://www.newURL.com
    • In the code, "oldURL.com" represents the landing page address your visitors will need to be redirected from while "http://www.newURL.com" represents the address you'd like your visitors redirected to.
    • There should be exactly one blank space between "oldURL.com" and "http://"
    • Don't add "http://www" to the (old) URL in the first part of the code![1]
    • The code "301" is most commonly used on redirected sites and means "moved permanently". Research other "300" codes to learn about other functions.
  5. Set the new URL destination. Change “http://www.newURL.com” to the domain address you'd like visitors to be redirected to.
  6. Save the new .htaccess file. Change the dropdown to “all files” and save the file as .htaccess with no extension.
  7. Create a backup. Rename any existing .htaccess files or html files with the same name to keep a backup copy. For example use the name .htaccessbackup so that you can find and recognize the file in case you need to do a restore of the previous code.
  8. Upload the modified file to the root directory of the old domain. Now that you've modified the code you need to put this file back so the old URL can read it and redirect as planned.
  9. Test the redirect. Open a new private browsing window and type the old domain name into your web browser. If you've done everything correctly it will redirect to the new site.[2]
    • Using a private browsing window simply ensures that your browser is accessing the new redirect instead of relying on cached data (data stored to help your most commonly visited pages load faster).
    • In lieu of a private browsing window, you can also clear your browser's cache through the browser preferences menu. For more information on how to do that, see Clear Your Browser's Cache.

Using a Redirection Service

  1. Check with your web host. If you're unsure of your own coding ability or just want to redirect a URL without digging into the code, there are several redirection services available and your current web host may be one of them. Many popular web hosts offer redirection services and the accompanying support to help you achieve your goals. Check on the features your current host/plan offers or contact them directly about what your options are.
  2. Pick a 3rd party service. If your web host doesn't offer redirection, there are many other options out there. Depending on what your redirection needs are you may be able to do this for free.[3]
    • Many services allow you to configure options for your redirect such as the type (permanent or temporary) or whether query parameters are passed along.
    • Very few redirection services will allow you to forward HTTPS (secure) links.
  3. Follow the instructions from the redirection service. Typically these services are extremely user-friendly and can help walk you through the process, prompting you at each step for the correct information.
    • Note: in some cases you'll still need to be able to edit the DNS (domain name server) records for the domain names you'd like to redirect. These are accessible through your web host.
  4. Update the DNS records. Your 3rd party redirection provider will let you know if this is necessary and you can access and edit these records from your web hosting account.
    • The instructions to edit DNS records this step will vary by the service used, but typically both the redirection service provider and your web host will have easy-to-follow instructions.

Using a Meta Command

  1. Access the code for the page you want to redirect. This is a different method that involves you changing the webpage's code directly so you'll first need to download the files associated with the URL(s) you'd like to redirect away from.
    • Note that in most cases using a Meta command is not ideal for your redirect. Webpages with Meta code redirects are often filtered by search engines since it’s a known spam technique.
  2. Open the code for edits. Use “Notepad” or a similar text editor to open the webpage's code file. Save a backup or duplicate copy before making your edits to the code as a safety measure.
  3. Amend the code. The Meta code goes after the "head" tag (<head>) in the page's code. Type in :
    .<META http-equiv="refresh" content="0;URL=http://www.newsite.com/newurl.html">
    • There is exactly one blank space between "refresh" and "content"
    • "0" here stands for number of seconds before the redirect happens.
    • "www.newsite.com/newurl.html" is the specific URL that the page is to be redirected to.
    • It's also possible to create a custom error message or an announcement that your sites has moved, but this may draw unwanted attention to your redirect![4]
  4. Save the file and re-upload to your old domain. If you are redirecting traffic from an old URL, it's likely that other changes have also taken place to your URL's code (e.g. the removal of your site content). What's important is that the URL code now contains the meta redirect code.
  5. Test the redirect. Type the URL into your browser directly or use a search engine to find it. The page should now redirect immediately to the new URL you specified in the code without any messages or landing points in between.

Using Other Coding Languages

  1. Find out what code your site is written in. For each programming language, the appropriate redirect code may be slightly different. If you're unsure of the answer to this question, contact your web host for more information.
  2. Research other redirect code. There are different coded commands for each language and several options to explore within each language. A quick internet search is likely to yield the appropriate code for your site.
    • For instance it's easy to search for and find code for PHP, ASP, ColdFusion and Javascript redirects online.[5]
  3. Test the redirect. After finding the correct code for your site, implementation will be quite similar to the other coding methods outlined. Afterwards always make sure to test the redirect by visiting your (old) URL to see if things work as planned.

Tips

  • Users of FrontPage (a once popular website admin tool) will need to modify .htaccess files in _vti_bin and the _vti_bin subfolders _vti_adm and _vti_aut.
  • While some websites use an error page explaining a change of URL and include a clickable redirect link, this less efficient than an automatic redirect and can end up costing your new site a significant percentage of visitors.

Related Articles

Sources and Citations