Redirecting a URL to another address using an htaccess file, meta tags, and more

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.[1]

Method 1
Method 1 of 4:

Coding an .htaccess 301 Redirect

  1. 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. 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.[2]
    Advertisement
  3. 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.[3]
    • 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. 4
    Type in the code. Paste the following code into the .htaccess text file: "redirect 301 /old/oldURL.com http://www.newURL.com"[4]
    • 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![5]
    • The code "301" is most commonly used on redirected sites and means "moved permanently". Research other "300" codes to learn about other functions.
  5. 5
    Set the new URL destination. Change “http://www.newURL.com” to the domain address you'd like visitors to be redirected to.
  6. 6
    Save the new .htaccess file. Change the dropdown to “all files” and save the file as .htaccess with no extension.
  7. 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. 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. 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.[6]
    • 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.
  10. Advertisement
Method 2
Method 2 of 4:

Using a Redirection Service

  1. 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.[7] 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. 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.
    • 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. 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.
    • Depending on your website host, you may be able to configure the redirection in your website settings.[8]
    • 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. 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.
  5. Advertisement
Method 3
Method 3 of 4:

Using a Meta Command

  1. 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.[9]
    • 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. 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. 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">[10]
    • 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. 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.
  6. Advertisement
Method 4
Method 4 of 4:

Using Other Coding Languages

  1. 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. 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.
  3. 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.
  4. Advertisement

Expert Q&A

  • Question
    Can you redirect a URL to a specific page?
    Stan Kats
    Stan Kats
    Professional Technologist
    Stan Kats is a Professional Technologist and the COO and Chief Technologist for The STG IT Consulting Group in West Hollywood, California. Stan provides comprehensive technology solutions to businesses through managed IT services, and for individuals through his consumer service business, Stan's Tech Garage. Stan holds a BA in International Relations from The University of Southern California. He began his career working in the Fortune 500 IT world. Stan founded his companies to offer an enterprise-level of expertise for small businesses and individuals.
    Stan Kats
    Professional Technologist
    Expert Answer
    Yes, you can—just use your website's settings to redirect your site to a different page. If your host doesn't have that type of setting, set up a very simple site that automatically redirects the visitor to another page.
  • Question
    Can I redirect a website that I don't own using only my computer?
    Community Answer
    Community Answer
    It depends on what you mean by redirect. If you mean to redirect incoming traffic from the website to wherever you want it to go, then the short answer is no. It's possible, but also illegal depending on where you are, and what the laws are. If you want to direct a link to a destination of your choice, use something like TinyURL or RarME.
  • Question
    Can it be sent straight to a message with no URL?
    Community Answer
    Community Answer
    You could write a javascript routine that just spits out whatever text you want it to say, but you'd still have to include that in your index.html page. At that point, you might as well just place your message in your index.html or home.html page. Then again, I'm no javascript expert. Check some of the javascript code libraries, you might find what you want; then you just cut and paste.
Advertisement

About This Article

Stan Kats
Co-authored by:
Professional Technologist
This article was co-authored by Stan Kats. Stan Kats is a Professional Technologist and the COO and Chief Technologist for The STG IT Consulting Group in West Hollywood, California. Stan provides comprehensive technology solutions to businesses through managed IT services, and for individuals through his consumer service business, Stan's Tech Garage. Stan holds a BA in International Relations from The University of Southern California. He began his career working in the Fortune 500 IT world. Stan founded his companies to offer an enterprise-level of expertise for small businesses and individuals. This article has been viewed 1,488,085 times.
How helpful is this?
Co-authors: 59
Updated: May 30, 2022
Views: 1,488,085
Article SummaryX

1. Open the .htaccess file on the web server.
2. Type redirect 301 /old/oldURL.com http://www.newURL.com.
3. Replace the "newURL" section of the code with the website you want to redirect to.
4. Save the file and re-upload if necessary.

Did this summary help you?
Advertisement