banner



How To Create A 301 Redirect

301 Permanent Redirects Title Image

A permanent 301 redirect informs search engines and other online services that an old link has been replaced by a new one. It's the recommended method for directing traffic from an existing page. This type of 301 redirect can be set up directly via the .htaccess file or in the cPanel interface, if available.

  • Common Uses of 301 Redirects
  • Set Up 301 Redirect via .htaccess file
  • Set Up 301 Redirect via cPanel

Common Uses of 301 Redirects

Some common uses of a 301 redirect in .htaccess:

  • Redirect individual files on the same domain.

    An old file has moved locations, or the information is now contained in a new file.

  • Redirect an old domain to a new domain.

    You've moved a website from an old domain to a new one, and you want any old links to go to the new site.

  • Force www. version of a domain or force non www. version of a domain.

    Visitors can access and link to your website through either example.com or www.example.com. With a redirect, you can set one of these as the preferred domain name that your site displays.

  • Redirect all files with certain extension.

    You used to have all of your files using an extension like .php and have converted everything to .htm so using a 301 redirect you can update all links to use the new extension.

Don't have time to read our article on how to set up a 301 redirect? Watch our walkthrough video.

Set Up 301 Redirect via .htaccess file

On a Linux server you would use your .htaccess file to implement a 301 redirect for your pages. We'll now show you how to edit the .htaccess file, then go over the different redirect options.

  1. Login to your cPanel.
  2. Under Files, click on File Manager.
    Access File Manager to Setup 301 Redirect in .htaccess
  3. Ensure that Show Hidden Files is selected by clicking Settings on the top right corner of the File Manager.
    View Hidden Files to See .htaccess
  4. Select the Document Root for: option, and choose your domain from the drop-down.
  5. Right-click on the .htaccess file and select Edit.
    Edit .htaccess File and Setup 301 Redirect
  6. If your .htaccess file is still not found after the previous steps, click on New File at the top-left, name the file .htaccess, and set the directory for the file to be created to /public_html/ or the document root of your site.
  7. You might have a text editor encoding dialog box pop-up, you can simply click on Edit to proceed.
    Edit .htaccess file - Setup 301 Redirect

Redirect files

To redirect individual files, like example.com/oldfile.htm to newfile.htm you can use a 301 redirect like this:

Redirect 301 /oldfile.htm /newfile.htm
single file 301 redirect

To redirect one specific file to another domain such as example.com/oldfile.htm to example.net/newfile.htm:

Redirect 301 /oldfile.htm https://example.net/newfile.htm
single file domain 301 redirect

Redirect domain

If you had an old domain such as example.com and you decided to use example.net for a website, you could setup a 301 redirect for the entire domain, so that old links to example.com carry over.

Sample of code from example.com domain's .htaccess file:

RewriteEngine on          
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.net/$1 [L,R=301,NC]
full domain 301 redirect

Force www. on domain

A search engine such as Google interprets example.com and www.example.com as essentially two separate websites. It is recommended that users pick one version they'd like search engines to display. By using a 301 redirect, users can specify which domain name is displayed on their site.

If you have a number of links on the web where people are linking to your site as example.com, but you would prefer your visitors end up at www.example.com instead, you can force this version of your domain with these rules:

RewriteEngine on          
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC]
force www 301 redirect

Force non-www. on domain

If you have a lot of links on the web where people are linking to your site as www.example.com, but you would prefer your visitors end up at example.com instead, you can force this version of your domain with these rules:

RewriteEngine on          
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301,NC]
force non www 301 redirect

Redirect files by extension

To re-direct all of one type of file to another, such as example.com/file.php to example.com/file.htm

RewriteEngine On          
RewriteCond %{REQUEST_URI} .php$
RewriteRule ^(.*).php$ /$1.htm [R=301,L]
file extension 301 redirect

You should now know how to properly setup 301 permanent redirects on your website to help ensure that search engines and visitors coming to your site from older links can still get to your new content.

Set Up 301 Redirect in cPanel

For users that host their sites on cPanel-based hosts, it is possible to set up redirects via the cPanel interface. This tool automatically adds the necessary code to the .htaccess file for the redirect to function properly.

  1. Login to cPanel.
  2. Click theRedirects button in theDomains section.
    301 Redirect Button cPanel
  3. You will then be on theAdd Redirect page. Click the drop-down box forType and choose either aPermanent (301) orTemporary (302) redirect.
    301 Redirect Type cPanel
  4. Click the next drop-down box and choose the domain you want to redirect.
    301 Redirect Protocol cPanel
  5. For the slash '/' field, enter any folder names (if necessary).
  6. Enter the address you want to redirect to in theRedirects to section.
    301 Redirect Target cPanel
  7. Choose if you want to "Only redirect with www." "Redirect with or without www." or "Do Not Redirect www."
  8. Check the box if you want to create aWild Card Redirect. This will add the the file/folder name after the url when it redirects. For instance, example.com/test.php would redirect to example2.com/test.php.
  9. ClickAdd when finished.
    301 Redirect Save cPanel

Congratulations, now you know how to create a redirect in your cPanel! Did you know? If you have a WordPress site, you can also create a 301 redirect directly in your dashboard.

Know you'll always be able to reach your customers when they need you with our Dedicated Hosting Services.

How To Create A 301 Redirect

Source: https://www.inmotionhosting.com/support/website/setting-up-a-301-permanent-redirect-via-htaccess/

Posted by: robertsonbeirch1984.blogspot.com

0 Response to "How To Create A 301 Redirect"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel