What is a 301 web page, website, domain name redirect, and force redirect?

With a 301 redirect, you can have just about any location move to another. Here we will list how to add a 301 redirect in the most popular ways. 301 redirects can help SEO by making all access to your website have a www. or not. This is said to tell Google to put all your page ranks on one URL. Also, if a page has moved and has a good ranking, Google might even move that rank juice to your new URL with a 301 redirect from that page to the new one. Keep in mind .htaccess code has to be exact or the entire website can break until it's fixed.

Force all traffic to use SSL (This includes all images and video, but does not work on all websites)

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

Force the domain name to use SSL (This is the most compatible way)

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

Redirect individual 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

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

Redirect 301 /oldfile.htm http://example.net/newfile.htm

Redirect an old domain to a new domain

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

Code in the example.com domain's .htaccess file:

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

Force the www. version of the domain to be used

A search engine like Google would see example.com and www.example.com as essentially two separate websites. They recommend you pick one version you'd like search engines to display and using a 301 redirect is a possible option.

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

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

Redirect all files with a certain 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]

Removal

To remove the most common (htaccess) website redirection, you'll need to use the redirect tool in cPanel or remove the code from the htaccess files in the website. You can access the htaccess file with FTP or the File Manager in cPanel. The htaccess file is located in the /pubiic_html and /www folders. It's a hidden file, so you may need to turn on showing hidden files in your FTP and the File Manager. Be careful when editing this file, it can break the website if done incorrectly.

Removing other forms of redirects requires more complexity, as they would be done from within the code of the website. It's most common to contact the app or script maker for this type of help. Otherwise, you would have to check each file in hopes of finding the code that was added for the redirect.

  • 301, redirect, www, seo, redirection, force ssl redirect, force domain ssl, website
  • 66 Users Found This Useful
Was this answer helpful?

Related Articles

How to flush your DNS cache

Your home computer creates a cache for all DNS settings. It does this to save time each time you...

What is the root login for my new VPS server?

The root login is the same password our system sent you in your welcome email. You just change...

What is the path to PERL?

The path to PERL in PERL script is:#!/usr/local/bin/perl

Do you troubleshoot scripts and apps?

Hello,Sorry, but troubleshooting sripts and apps needs to be done by the scipt maker or a...

How to use PHP-CLI

You would call '/usr/local/bin/php' if you need the php-cli binary, and '/usr/bin/php' if you...