In this tutorial, I will show you how to redirect a domain without changing the URL.
This is very useful especially when you don’t want to change your URL and want to keep using the same old URL of the domain. I will provide you with different ways to go about these and the example codes you can use to redirect your domain without changing the URL.
Here are what I will be covering:
- Redirect and keep everything after the URL
- Redirect a domain to a specific url
- Re-directing an IP address
Let’s get started.
How To Redirect A Domain Without Changing The URL
- Log into your cPanel.
- Scroll down to the Files section and select File Manager.
- In the File Manager, open the public_html folder and locate the .htaccess file.
- Right click on the .htaccess file and select Edit. A popup screen will appear, go ahead and click on Edit.
You can now go ahead to set up the different redirection parameters that you want.
Redirect and keep everything after the URL
If you have many visitors coming to your DomainA.com and want to redirect them to DomainB.com without changing the domain URL, you can use this type of redirection in your .htaccess file.
With this type of redirection, whenever visitors come to DomainA.com, they will get content that is in DomainB.com without any change in the URL.
Copy the code below and paste it into your .htaccess file.
RewriteCond %{HTTP_HOST} ^DomainA.com
RewriteRule ^(.*) https://DomainB.com/$1 [P]
Redirect a domain to a specific URL
If you want to redirect visitors to a specific page or URL of a website without changing the domain, you can use this type of redirect.
This type of redirection is very useful especially if you have an external blog, and you want to redirect visitors to another page on another domain, you can use this redirection to do that easily.
With this redirection, whenever visitors enter DomainA.com, they will be automatically redirected to the specific page that they want.
Copy the code below and paste it into your .htaccess file.
RewriteCond %{HTTP_HOST} ^DomainA.com
RewriteRule ^(.*) https://DomainB.com/PathToPageHere [P]
Redirect an IP address
To redirect an IP address to an IP address to a specific URL, simply copy the code below and paste it into your .htaccess file.
# Redirect all IP address (replace the ## with the IP address numerals) to same https://domain_name.com
RewriteCond %{HTTP_HOST} ^##.##.##.##
RewriteRule (.*) https://domain_name.com/$1 [R=301,L]