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!

Like this Article?

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,962 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
8,247 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
8,247 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
8,247 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

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.

8 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!