How to redirect URL

Author: Ellen Moore
Date Of Creation: 11 January 2021
Update Date: 1 July 2024
Anonim
How (and Why) to Redirect a URL
Video: How (and Why) to Redirect a URL

Content

There are several reasons to use URL redirection.You can move content from one domain to another, thus, you will need to redirect visitors from the old site to the new one. You can have multiple domains associated with the same site. Or you need to redirect the site without the "www" to the correct site page. Creating an error page with a link to a new site is an easy redirect, but not always the best. For a site that has a lot of traffic and good search results, such a redirect would mean starting from scratch. In addition to this, users may not pay attention to the link with the name of the new site. In the methods described below, traffic still goes to the old domain, but is also redirected to the new one. As the search engines update their databases, the new domain will keep all search results. The difficulty of mastering the URL redirection process depends on what language the site is written in and how much experience you have in editing code.


Steps

Method 1 of 5: Prepare a new domain and files

  1. 1 Make sure the new domain belongs to your hosting account.
  2. 2 Download files from the old domain to your computer. Keep folder structure and file names.
  3. 3Upload files from the old domain to the new one.
  4. 4Click the Start button and open Accessories> Notepad in Programs to open a text editor.

Method 2 of 5: Using META Command to Redirect URL

  1. 1Open the “index.html” file or the file you want to redirect.
  2. 2Place the cursor after the HEAD tag.
  3. 3 Enter the following:
    • meta http-equiv = "refresh" content = "0"; URL = "http://www.newsite.com/newurl.html">
    • "0" is the number of seconds after which the redirection will occur. www.newsite.com/newurl.html - site name and specific page to redirect to.
  4. 4 Add text to create an error page. Add a notification that the site has moved to a new page. Add the name of the new site with a link that can be used to manually navigate to the new site. Change the refresh time of the page so that the visitor can read the required information.
  5. 5Save the file.

Method 3 of 5: Using an htaccess file to redirect

  1. 1 Find the file if your site is running on an Apache server. The htaccess file on the Apache server contains error requests, redirects, and other requests.
  2. 2 Browse the list of 300 http status codes. Code "301" is used in case of redirection and means "moved permanently".
  3. 3 Enter the following code into the text file:
    • RewriteEngine On
      RewriteRule ^ (. *) $ Http://www.newdomain.com/$1 [L, R = 301]
    • “L” is the last indication, “R” is the redirect, parameter “301” is the final redirect.
  4. 4 Find information on how to redirect URLs with spaces in the title, dynamic pages, sub-domains, on the Internet.
  5. 5Change “newdomain.com” to the name of the new site.
  6. 6 Click "Save". Change the option for showing files to All Files. Save the file as .htaccess without the extension.

Method 4 of 5: Uploading and Testing the File

  1. 1 Rename any existing .htaccess files to keep the backup. Use the file name .htaccessbackup or something similar to easily find the file and recover.
  2. 2Upload the modified file to the root folder of the old domain.
  3. 3 Enter the old domain name into the browser. You should be redirected to the new site.

Method 5 of 5: Using a different code

  1. 1 Find out what language the site is written in. There are different codes for each language.
    • You can find redirect codes for PHP, ASP, Coldfusion and Javascript online.

Warnings

  • Meta-refresh pages are filtered by search engines, as this is a common spam method.
  • FrontPage users do not need to modify the .htaccess files in the _vti_bin folder and in the _vti_adm and _vti_aut subfolders.