There are several reasons for redirecting a URL and a few basic ways to do it. For a website that already has a lot of traffic and achieves good results in the search engine but needs to change its domain address, a redirect is a good choice for the transition period. The internet traffic will still go to the old domain, but will then be automatically redirected to the new domain. Over time, as search engines update their databases, the new domain itself will generate search results. A redirect can also redirect several different URLs to a single website and shorten complex URL addresses. The method of redirecting URLs depends on the code your website is programmed into and how much confidence and experience you have editing that code.
Method 1 of 4: Encrypting a.htaccess 301 redirect
Step 1. Check if your website is running on an Apache server
This is necessary to write a forward with.htaccess - check with your web host if you are unsure about this.
Step 2. Locate and download your.htaccess file
An.htaccess file is a file that web servers refer to for information about error handling, security, and redirect requests for your site. Look in the root folder (where all your website's files are stored) and download the file so you can edit it.
Step 3. Create a.htaccess file
If there is no.htaccess file in the root directory, you can create one using an application like Notepad (or a similar plain text editor). The code for the file is shown in the next step.
- Make sure to save the.htaccess file with a "." in the beginning.
- Note that this file has no extension (e.g. ".com" or ".txt")
Step 4. Type the code
Paste the following code into the.htaccess file:.redirect 301 /old/oldURL.com
- In the code, "oldURL.com" represents the address of the page from which your visitors are redirected to "http://www.newURL.com", or the address your visitors are redirected to.
- There must be exactly one space between "oldURL.com" and "http:"
- Do not add "http://www" to the (old) URL in the first part of the code!
- The code "301" is most commonly used on redirected sites and means "moving permanently". Research other "300" codes to learn about other features.
Step 5. Indicate the new URLChange “http://www.newURL.com” to the domain address where your visitors should be redirected.
Step 6. Save the new.htaccess file
In the file selection, choose “all files” and save the file as.htaccess without extension.
Step 7. Create a backup
Rename any existing.htaccess files or HTML files in such a way that you have a clear backup. For example, use the name.htaccessbackup so that you can find and recognize it, in case you need to restore previous code.
Step 8. Upload the modified file to the root of the old domain
Now that you've changed the code, you need to restore this file so that the old URL can read and redirect it as intended.
Step 9. Test the redirect
Open a new private window and type the name of the old domain into your web browser. If you did everything correctly, it will redirect you to the new site.
- Using a private window ensures that your browser opens the new redirect instead of relying on old cached data (data saved to load the most visited pages faster).
- Instead of a private window, you can also clear your browser cache through your browser's preferences menu. For more information, read wikiHow articles about clearing your browser's cache.
Method 2 of 4: Using a redirect service
Step 1. Check with your web host if they can arrange the redirection
If you're unsure of your own programming skills or just want a redirect from a URL without digging into code, there are several redirect services available and your current web host is one of them. Many popular web hosts offer redirect services and related support to help you achieve your goals. Check the possibilities with your current host/plan, or contact them about the possible options.
Step 2. Choose another service
If your web host doesn't offer redirection, there are many other options. Depending on the requirements of your redirect, this may be free of charge.
- Many services allow you to configure options for the redirection, such as the type (permanent or temporary) and whether query parameters are passed.
- Few redirect services will allow you to redirect HTTPS (secure) links.
Step 3. Follow the instructions of the redirect service
Usually, these services are very user-friendly and can guide you through the entire procedure, prompting you for the correct details at every step.
Note: In some cases you will still need to edit the DNS (domain name server) records to specify the domain names you want to redirect. These are accessible through your hosting provider
Step 4. Update the DNS records
The provider of the redirect service will let you know if this is necessary and you can access and edit these records from your web hosting account.
The instructions for editing the DNS records in this step depend on the service being used, but both the redirect service provider and your web host will usually have easy-to-follow instructions
Method 3 of 4: Use a Meta command
Step 1. Open the code for the page you want to redirect
This is another method where you change the code of the web page directly, so you will first have to download the files associated with the URLs you would like to redirect.
Note: In most cases, a Meta command is not ideal for a redirect. Web pages with Meta redirects are often filtered by search engines as it is a well-known spam technique
Step 2. Open the code for edits
Use the Windows Notepad or a similar text editor to open the code from the web page. To be safe, make a backup or duplicate copy before changing the code.
Change the code. The Meta code comes after the "head" tag () in the HTML code. Type:.
- There is exactly one space between "refresh" and "content"
- The "0" here stands for the number of seconds before the redirect is executed.
- "www.newsite.com/newurl.html" is the URL the page will redirect to.
- It is also possible to provide a custom error message or a notification that your site has moved, but this could draw unwanted attention to the redirect!
Step 2. Save the file and upload it again to the old domain
If you're redirecting traffic from an old URL, it's likely that other changes have occurred to the URL's code as well (for example, removing content from your site). Importantly, the URL code now contains the meta code of the redirect.
Step 3. Test the redirect
Type the URL directly into your browser or use a search engine to find it. The page should now lead immediately to the new URL you specified in the code, without any messages or other sites in between the final web page.
Method 4 of 4: Using other programming languages
Step 1. Find out what programming code the website is written in
The correct redirection code may differ slightly for each programming language. If you are not sure about the answer to this question, please contact your web host for more information.
Step 2. Research other redirect code
There are different coded commands for each language and different options to explore within each language. A quick internet search will probably get you the right code for your site.
Step 3. Test the redirect
After finding the right code for your site, the implementation will be quite similar to the other coding methods described. Always make sure to test the redirect/redirect afterwards, by opening your (old) URL and checking if everything works as planned.
- Users of FrontPage (once a popular tool for websites) will need to modify the.htaccess files in _vti_bin and _vti_bin subdirectories _vti_adm and _vti_aut.
- While some websites use an error page explaining a URL change and pointing out a redirect link that can be clicked, this is less efficient than redirecting the visitor automatically and can end up costing your new site a significant percentage of visitors.