Site icon DED9

How to redirect domain

Redirect domain means a permanent change of direction from one address to another so that all the points and positions of the previous link are preserved and its value is not lost. In this way, the user is redirected to a page and address different from the address he saw in search engines or the address he entered in his browser. One of the important reasons for using the 301 site redirect is to preserve the link, SEO, and the position of that link in search engines. 301 redirect informs search engines that this redirection is applied permanently, but in 302 redirects, the situation is a little different, in other words, 302 is considered a temporary redirect.

CPanel host and Direct Admin host also have sections for redirecting addresses.

Redirect one address to another address in cPanel,  and redirect site addresses with the htaccess file. At the door

The most common uses of 301 redirects

In what conditions is 301 redirects used?

  • Redirect a bunch of specific files in the same domain
    For example, some files are out of date, or their location has changed or they should be redirected to a new file for any reason.
  • Redirect old domain to new domain
    For example, your domain is unused or outdated and you want to transfer the domain with all its links to a new domain with corresponding links.
  • You want to use the domain address with www or without www immediately.
    For example, the site should be as example.com or www.example.com displayed . In general, one of these two methods should be selected.
  • Redirect a series of files with specific extensions
    For example, a series of files with the extension php. to files with the extension. Redirect.

How to redirect the site

Sometimes, for various reasons, we decide to change the entire domain and its addresses so that the user opens any link from the previous domain in his browser and is transferred to the corresponding address in the new domain. For example, if our domain was test.com and the user opens the address test.com/contact-us in his browser, he will be redirected to the address test.ir/contact-us. In simpler words, in addition to redirecting the domain address, the site’s internal links can also be redirected to their corresponding addresses. Well, the work got a little complicated, that is, we need to manage all the addresses of our site. In this article, we will address the 301 redirect, one of the biggest challenges among users.

Where is the htaccess file?

  1. Log in to your host’s control panels with the help of the following instructions.
    Login to cpanel control panel, login to direct admin
  2. After entering the host, click on the gear symbol or the host settings on the top right side of the page.
  3. Enable the Show Hidden Files option.
  4. Go to the File Manager section of your host.
  5. htaccess file in the path of the destination domain (the domain to which the redirection is made). find the Pay attention to the htaccess file. It is secret. If you don’t find it, get help from the tutorial on how to view hidden files in cPanel.
  6. on the htaccess file. Right click and select Edit. to be directed to its editor section. And in the next steps, you can add redirect codes to it.

 

[Possible htaccess file. not available on your host, you can create it manually. for this purpose:

 

  1. Click on the New File option in the toolbar of your host. to create a new file.
  2. Name it htaccess. put.
  3. This file should be placed in public_html path.

Then follow the steps below based on the type of redirect you want to do…

Redirect domain with all its internal links

Redirect a domain link to a corresponding link from a new domain: Imagine you want to redirect a file from the current domain to another file from the new domain.

 

For example, file.html from the domain example.com should be redirected to file.htm from the new domain i.e. example.net. (The address example.com/file.html should be redirected to the address example.net/file.html.)

If you intend to do this type of redirection from the main domain to the domain name, you must create the desired domain name before starting. For this purpose, you can take help from the tutorial on creating a domain in cPanel .

Now, if you want to redirect your old domain to the new domain, you should use 301 redirect. In this way, all the internal links of the old domain will be completely redirected. For this purpose, you must go through the following steps:

  1. According to the manual, where is the htaccess file? mentioned at the beginning of this article, htaccess file. find the
  2. Open the editor of this file.
  3. Put the following code in the 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]

Note: instead of example.com and example.net in the code above, enter your domain names.

Be careful, the code snippet above will redirect the domain along with all its internal links to the corresponding addresses. If you want to redirect the entire site to the desired domain, use the code below. In this way, every link from the current site will domain address , but in the previous redirect method, we had the corresponding links. be redirected to the desired

Redirect 301 / http://www.domain.com/

Redirect specific link

Redirecting the intended link to another link from the same domain ( individual redirect): Sometimes it is necessary to redirect a specific file, page or link from the domain to another address in the same domain. For example, a page called page1 should be redirected to page2.

 

In such a situation, to redirect the following piece of code in the htaccess file. insert

Redirect 301 /page1 http://www.domain.com/page2

The formula of the above code fragment is as follows: first, we insert the name of the source page , put a space, then write the second link in full.

Redirect in WordPress

Due to the popularity of the WordPress content management system and for the convenience of users regarding redirects, several plugins have been developed. Regarding redirect links in WordPress, you can get help from the following tutorials:

How to redirect links to one another in WordPress , what is redirect 301 and what is its use?

Tip: If you don’t want to use the plugin, you can also get help from the ” What is 301 Redirect ” tutorial .

Redirect site to subfolder and vice versa

Sometimes it is necessary to redirect the content of your site to the content of one of the subfolders. In such a situation, you should add the following piece of code in the htaccess file. The source entered:

Redirect 301 / http://www.example.com/subfolder/

The opposite of this situation is also possible, for example, you want the content of the subfolder to be redirected to the content of another domain, in such a case, we use the following code snippet:

Redirect 301 /subfolder http://www.domain.com/

Note: instead of www.example.com, enter the domain name of your site and instead of the word subfolder, enter the name of the subfolder you want.

Redirect the old domain to the new domain

This piece of code is also suitable for redirecting the old domain to the new domain:

RewriteEngine on
 RewriteBase /
 RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

In this training from the Fa host knowledge base , it was tried to discuss the site’s redirect codes. Each type of redirect requires its own coding. The redirect code of the site is completely different from the redirect code of the link in question, and also the redirect of the entire site is completely different from the redirect of the domain. Accordingly, in order to prevent damage to the site’s SEO, you must be very careful about the wrong code in the htaccess file. Do not insert

Exit mobile version