In this article, we will give you 2 ways in how you can go about redirecting your site to another URL, without changing the domain.

Example 1: Redirect and keep everything after the URL

The first option will show all of the same content on one URL as you would another. For example, if you just changed your domain to DomainB.com, but you still have plenty of visitors coming to DomainA.com, you would use this to show them all of the existing content that is located on the new domain, without the need to update both websites.

To do this, you would modify your .htaccess file for the domain that your users will go to, and insert these lines of code:

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

If you are using the file manager in cPanel, be sure that you have the option to show hidden files selected.

What does the above redirect do?
After adding this line into your .htaccess file, you will be able to go to DomainA.com/YourPage and it will show the content from DomainB.com/YourPage

Example 2: Redirect a domain to a specific url

There is another way you can do your redirect to show a specific URL, but keep the domain the same as well. If you want visitors to go to DomainA.com with a specific page in mind when doing so, you may use this code:

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

You would use this method if, for example, you had an external blog such as one on blogspot.com or maybe a shopping cart on etsy.com that you want people to visit your domain without fully hosting the domain there. Now, visitors can access your site using your domain, but see the content of an external URL.

Example 3 Re-directing an IP address

Occasionally, there will be a request to re-direct an IP address to a specific URL. The following code shows how this can be done in the .htaccess file.

# Redirect all IP address (replace the ## with the IP address numerals) to same http://domain_name.com
RewriteCond %{HTTP_HOST} ^##\.##\.##\.##
RewriteRule (.*) http://domain_name.com/$1 [R=301,L]

Stipulations / Please read

Warning: If using the first option, search engines such as Google or Bing will see multiple sites with the same content and can cause ranking drops in one, or both of the sites. From an SEO standpoint, your best option is to create 301 redirects instead.

If you opt for the second option, and are using absolute links on your site (meaning your links go to the full URL and not just an individual file) any links will go to the original site that is associated with that link.

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Related Questions

Here are a few questions related to this article that our customers have asked:
Can I use .htaccess to load my site from a different folder?
Would you like to ask a question about this page? If so, click the button below!
Ask a Question
n/a Points
2014-07-03 2:08 pm

I wanna know where should I put this code?

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

Thank you

Staff
9,968 Points
2014-07-03 2:14 pm
Hello mo,

You would want to place that code towards the top of your .htaccess file.

You also want to make sure that the Apache Rewrite engine is on, so the full code would look like:

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


Let us know if that works!

- Jacob
n/a Points
2014-08-08 12:01 pm

I've got this at the top of my .htaccess, but it's not working. :(

 

# Turn on the Rewrite EngineRewriteEngine OnRewriteCond %{HTTP_HOST} ^tomorrow.coe.uga.eduRewriteRule ^(.*) http://www.coe.uga.edu/$1 [P] 
Staff
9,525 Points
2014-08-08 12:42 pm
Hello Daniel,

Thank you for your question. Your code looks pretty accurate, but you may have to add the $1 to the rewrite condition. For example:

# Turn on the Rewrite Engine
RewriteEngine On
RewriteCond %{HTTP_HOST} ^tomorrow.coe.uga.edu/$1
RewriteRule ^(.*) http://www.coe.uga.edu/$1 [P]


If you have any further questions, feel free to post them below.
Thank you,

-John-Paul
2014-08-08 12:57 pm
Still didn't work. :\

It's always me with the "simple" solutions failing. I swear my career is 2 years behind because of technical glitches outside my control. :)
Staff
9,525 Points
2014-08-08 1:33 pm
Hello Daniel,

Thank you for the additional information. Since it depends on your actual site, there is most likely something inferfering with the code.

For example, if you are using a CMS such as Wordpress, or Joomla, or Concrete5, they have rules in place already.

You could also have other rules in the .htaccess causing problems, you should check them as well.

Can you provide a link to the website so we can test it out?

If you have any further questions, feel free to post them below.
Thank you,

-John-Paul
n/a Points
2014-07-28 11:12 am

How is this different from doing a plain redirect? Is it possible to show contents from DomainB but show DomainA url?

Staff
9,525 Points
2014-07-28 11:33 am
Hello garry,

Thank you for your question. By "plain redirect," I think you mean creating a redirect in your cPanel. This just creates a redirect such as:
example1.com ----> example2.com

To show contents from DomainB but show DomainA url there are 2 options:

Park domain


Redirect Using .htaccess file


If you have any further questions, feel free to post them below.
Thank you,

-John-Paul
n/a Points
2014-08-27 5:39 pm

Hi,

For the moment i am using DirectAdmin, but acting as my own reseller i think i own full access to www.frituurrombout.be

The goal is to show the content of www.romboutmechelen.be but the URL bar should simply state :  http://www.frituurrombout.be

For the moment there is nothing configured in www.frituurrombout.be, but in future i might want to install a WordPress site, so that i can show more pages than just the content of www.romboutmechelen.be

I like your idea of the second option in the article.  But don't know what to put in "path to get there [p]"

Can you type it out for me ?

Many thanks in advance.

Here's my take :

 

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.frituurrombout.be
RewriteRule ^(.*) http://www.romboutmechelen.be/index.html [P]
Staff
17,331 Points
2014-08-27 6:08 pm
Hello Peter,

The path you're referring to has to do with the webpage that you're trying to point to. So, if the page is in a certain folder, then path would look like this: http://www.domainname.com/folder/filename.php. I hope that helps explain the issue.

Regards,
Arnel C.
n/a Points
2014-10-01 9:55 pm

Hi. 

Question:

I have a domainA.com and changed my url to domainB.com. As i had maintained urls friendly, i want visitors on going to domainA.com/page1 to be redirected to domainB.com/page1, as the content and url are the same, just changed by domain.

Is it this that is covered on Example 1?

Staff
9,525 Points
2014-10-02 9:31 am
Hello Ricardo,

Thank you for contacting us today. Yes, that is what is is covered in Example 1: Redirect and keep everything after the URL.

If you have any further questions, feel free to post them below.

Thank you,
John-Paul

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

12 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!