Beware potential phishing attack. See the full details here.

Hosting > htaccess

3 minute read

How to create url redirects in .htaccess


Many times you want to redirect/forward your domain to another domain but you don’t want to change the URL of your domain after the redirecting your domain. You want to show the URL as it was showing before redirection.

How to redirect domain without changing the URL

In this article, we will share all the ways by which you will know how to redirect without changing the URL.

1. Redirect and keep everything after the URL.


2. Redirect a domain to a specific url.


3. Redirecting an IP address.

1. Redirect and keep everything after the URL



If you have a large number of visitor who are typing websiteA.com in their browser and you want them to redirect to websiteB.com without changing the URL then you can set this kind of redirection using the .htaccess file of your hosting account.

You need to enter a redirection rule in your .htaccess file as mentioned below. By doing this whenever a visitor will type websiteA.com on their browser then the content of websiteB.com will be displayed on their browser without changing the URL.

You can modify your .htaccess file and paste the below code in the top of your .htaccess file.


RewriteCond %{HTTP_HOST} ^DomainA.com
RewriteRule ^(.*) http://DomainB.com/$1 [P]


2. Redirect a domain to a specific url


If you want to redirect your visitor to a specific page of a website then you can set redirection using this way. You simply need to define that specific page in your .htaccess file of your hosting account.

By doing this whenever your visitor will type websiteA.com in their browser then they will automatically redirected a specific page of your website that you will mention in the code.

You can simple paste the below code in the top of your .htaccess file for redirecting a domain to a specific URL of a website.


RewriteCond %{HTTP_HOST} ^DomainA.com
RewriteRule ^(.*) http://DomainB.com/PathToPageHere [P]


Note:You can use this method if you have any separate blog or website which you want to display as a separate website. For Example: If you have a website related to cars and you have created a category Luxury Cars in your website and then you can register a domain luxurycars.com and set this kind of redirection to your website’s page of “Luxury Cars”.

So when your visitor will type luxurycars.com in their browser then they will automatically redirected to your that


3. Redirecting an IP address


Sometime web master want to redirect a specific IP of his hosting to a specific URL of a website. You can easily do it by adding the below code in the .htaccess file of your hosting account.

RewriteCond %{HTTP_HOST} ^XX.XX.XX.XX
RewriteRule (.*) http://domain_name.com/$1 [R=301,L]



Note: You need to replace the XX.XX.XX.XX with actual IP address that you want to re-direct another or your website.

I hope you are able to set the redirection using this steps by step guide. If you are facing any difficulty or facing any kind of error then you can contact our support team or chat support team. They will help you to resolve your issue.