Redirect urls correctly using cPanel and htaccess

Hosting Mautic QuickStart -50% with support in Spanish
24 hours and free training

Send up to 1,000,000 emails/year. Mautic support in Spanish 24 hours, 365 days

For the needs of redirecting web traffic, or to prevent us from being penalized in our positioning for displaying duplicate content (same website loading from different parked domains), redirects are necessary and important when we work with the same domain with a different extension or we want to bring traffic to a single domain.

Redirections allow us or a particular page to a different URL of the same Hosting or an external one.

For example, if you have a very long URL that cannot be shortened, you can use redirection to add a direction to a short URL. Users can access the content of the long URL through the short URL without affecting your SEO.

What is a Redirect?

a redirect >www is a rule on your web server that transmits all traffic from the web version no www from your domain to version with wwwor vice versa.

The HTTP protocol used on the web has a numerical system to identify the status of page requests. the status code 301 indicates that the requested page or resource has been “permanently moved”.

Types of redirect error codes:

  • 300 Multiple Choices: More than one possible answer.
  • 301 Moved Permanently: THE requested URI has changed.
  • 302 Not Found: The requested URI has temporarily changed.
  • 303 See Other (since HTTP/1.1): The server will direct the client to another resource at another URI.
  • 304 Not Modified: The answer has not been modified. The cached version is still used.
  • 305 Use Proxy (since HTTP/1.1): The destination or result will be accessible from a proxy, for security.
  • 306 unused: No longer used.
  • 307 Temporary Redirect (since HTTP/1.1): The same semantics as in a 302 apply, but the UserAgent cannot change the HTTP method used.
  • 308 Permanent Redirect: The resource has been permanently moved to another URI.
See also  How to get the first sales with PrestaShop -

By applying, for example, a www redirect it is important that it returns a 301 status code so search engines know which URL should be indexed.

When migrating a website from one domain to another, it is very important that the links you built on your old domain are not broken. Proper redirection of all pages from the old domain, in the same location, to the new domain will ensure that visitors from the old domain end up in the right place.

A failure (Error 404) in this action will cause a loss of visitors, as well as penalizing the positioning in search engines.

These types of redirects can be done manually:

RewriteEngine On RewriteCond %{HTTP_HOST} ^olddomain.com$ RewriteCond %{HTTP_HOST} ^www.olddomain.com$ RewriteRule (.*)$ http://www.newdomain.com/$1

What is the .htaccess file?

The file .htaccess it’s a “hidden” file (the . in front of the name indicates that it is a hidden file).

In order to view it you must:

  1. Access your cPanel.
  2. Go to the File Manager (it opens a dialog and one of the options is “Show hidden files” which should be selected).
  3. Navigate to folder /public_html (where we interpret you have the web).
  4. There you can find the file .htaccess (not to be confused with htaccess.txt which is visible).

It is important to make sure that mod_rewrite is enabled on your server (Yes for clients). Verify that the following line appears somewhere in your file .htaccess above the rule you are going to add:

RewriteEngine On

We assume that your web server uses Apacheso you should be able to add those lines to your file .htaccess located at the root of your website.

It is possible to create rules that redirect URLs that have a certain pattern to a new location.

Since these redirects involve complex regular expressions, we don’t cover them in this article.

An SEO professional can help you create these more complex and situation-specific rules. Just make sure you use a 301 redirect for relocated content.

See also  Contact Form: Error 1 An error has occurred while...

Any other type of redirect will not preserve your search engine rankings.

Recommended reading:


How do I perform a Redirect from cPanel?

The process is simple and I leave it here summarized in steps:

  1. Access your Hosting Panel (cPanel or WePanel), Domains, redirect.
  2. Select the type of redirect you want to perform from the menu Guy.
  • Option 1: Permanent 301 Redirect which will notify the visitor’s browser to update its records.
  • Option 2: Temporary 302 Redirect which will not update the visitor’s bookmarks.
  • Choose **All Public Domains** (All Public Domains) or a specific domain name on the menu.
  • Use the option **All Public Domains** (All Public Domains) to redirect all the domains of your cPanel.
  • In the text box to the right of the domain selection menu, enter the rest of the URL you want the server to redirect to.
  • Under Redirects, in the text box, type the URL you want to redirect users to (1).
  • Select one of the following options:
    • Redirection with www only redirects users who enter www in front of the page name.
    • Redirection with or without www. This option will redirect all users, regardless of whether the www prefix is ​​included. in the URL.
    • Do not redirect users who enter www. in the URL.
  • Select the option Wildcard Redirect (Wildcard Redirect) if you want to redirect all files within a directory with the same file name to the new directory (two).
  • click on Add.
  • 1: You must specify a protocol in this text box. For example, http://, https://, or ftp://.

    two: For example, if you enable the redirect wildcard option and domain1.com redirects to domain.comso if a visitor tries to access the URL http://domain1.com/image.jpg will be redirected to the URL http://domain .com/image.jpg.

    A common case is to perform a 301 redirect if you want to redirect only the traffic of a certain page ancient to a new page, which you can do by adding to the file .htaccess the following code:

    See also  Installation of SSL certificate and redirection from http to https

    Redirect 301 /old_path/old_page.htm http://www.domain.com/new_page.htm

    The redirections must always be inserted at the beginning of the .htaccess file, either in the root folder of the Hosting or of the folder of the installation that is going to manage said redirections. If these redirects appear at the end of the .htaccess file, they won’t work properly.

    How do I remove a redirect?

    If for some reason it no longer makes sense to maintain a previously made Redirect, you can (and should) remove it so that your traffic and positioning are not affected. Remember that Google doesn’t like broken links (404).

    • Click the button corresponding to the redirect you want to remove.
    • To confirm that you want to remove the redirect, click Yes.
    • To keep the redirect, click Nope.

    Video

    In the following video I explain how to handle 301 Redirects from your Hosting Panel (cPanel).


    Remember that you must later edit the .htaccess file of the website where you apply the redirection and move the redirection codes applied by cPanel to the top of the file itself so that they are the first thing that Apache interprets.

    Conclusions

    Redirections put order in those urls that have changed over time, have disappeared because the contents were removed or are simply not reachable for any reason not discussed in this article.

    Always carry out 301 redirects, especially if you detect that you have 404 errors in your tool Tracking Errors in Google Search Console.

    Help us improve our content by sharing your opinion

    Member of the technical support team.
    Coordinator of contents in the Blog and in Youtube.
    Technical support in CyberProtector. Teacher at University

    Loading Facebook Comments ...
    Loading Disqus Comments ...