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
11,023 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
11,023 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
11,023 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
18,513 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
11,023 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
n/a Points
2014-11-08 3:44 am

Example:1 not working....i Want to redirect my domain ludhianaweddingvendors.com to ludhianaweds.com keeping rest of the URL same also changing with the new URL in address bar. But m failed....Any help ?? Thanks in advnace...

Staff
20,888 Points
2014-11-10 10:29 am
Hello Ashish,

I tried the code you referenced on my server and it worked fine. This code is intended to allow a domain name different from the primary to display the content of the primary under the second name. For example, if your primary domain name is 'example.com' and you want to allow 'examole.net' to be used and show that same data, you would set it up like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.net
RewriteRule ^(.*) http://example.com/$1 [P]


Setting it in reverse order causes a proxy error on the server.

Kindest Regards,
Scott M
2014-12-03 1:56 am
Thanks Scott...I really appreciate your help... I am also facing problems in making URLs seo friendly by trailing slash and removing extensions from URLs by trailing slash.. The code i am using in my .htaccess is
Options +FollowSymLinks
Options -Multiviews
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+)/$ $1.php
RewriteRule ^([^/.]+)/([^/.]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

RewriteRule ^/([a-zA-Z0-9]+)/$ vendorlist.php?bcat=$1
RewriteRule ^([^/.]+)/([^/.]+)/?$ /vendor.php?bcat=$1&vendor=$2

It only remove extensions if i use it written as above. In case using seo friendly urls it gives an error 404. But if i change code like this

Options +FollowSymLinks
Options -Multiviews
RewriteEngine on

RewriteRule ^/([a-zA-Z0-9]+)/$ vendorlist.php?bcat=$1
RewriteRule ^([^/.]+)/([^/.]+)/?$ /vendor.php?bcat=$1&vendor=$2

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+)/$ $1.php
RewriteRule ^([^/.]+)/([^/.]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
Then it only make urls SEO friendly. Error 404 occurs on extension removal.
Please help me out of this, Thanks in advance....
Staff
18,513 Points
2014-12-03 11:54 am
Hello Ashish,

Thanks for the question. We unfortunately can't write the code for you, but we do try provide solutions for articles that we provide for issue like redirects in .htaccess. In your case, if you are using a software like a ecommerce software then you may want to consider possible extensions or modules that you can add to resolve this type of problem. If you want to figure out the code, please consider this post which discusses the removal of extensions and the forcing of www and trailing slashes.

Regards,
Arnel C.
2014-12-04 3:03 am
Hello ARN Priceless thanks for the link. It worked for me completely what i was looking for last almost 7 days. Thank you so much....
n/a Points
2014-12-02 4:40 pm

How do you redirect ALL other domains to a new domain? These example reference how to redirect a domin if you know the domain that will be used first.. What if you don't know the domain, or have too many to add/update?

Staff
10,022 Points
2014-12-02 5:03 pm
It is a much better idea to add each domain that you are redirecting from as a RewriteCond, but to redirect all domains, you would simply use the following:

RewriteRule ^(.*) http://DomainB.com/$1 [P]

n/a Points
2014-12-04 8:53 am

We have a domain Domain.in on Registrar1, hosted with Registarar2 with a landing page but emails configured, and now wish to just redirect the same to Domain.co, without disturbing the mails and letting them be hosted with Network Solutions.

I've just set a domain forwarder from Domain.in to Domain.co in Registrar1, and Domain.co is hosted with InMotion but registered on Registrar1 and is working fine since I've set the Name Servers to point to IMH.

However, if i point the nameservers on Domain.in also, then it screws up the MX records and mail propagation.

Am i doing something wrong - should i do anything else except the domain forwarding?

Staff
11,023 Points
2014-12-04 11:58 am
Hello Om,

Thank you for contacting us today. The MX record for Domain.co, is as follows:
0 Domain.co

This means that the email is going to be hosted wherever Domain.co is hosted.

If you want to host it elsewhere, create a subdomain, for example:
mail.Domain.co

This subdomain must be created with your DNS host, and your registrar.

Then, point the 'A record' for mail.Domain.co to the server that is hosting the email.

Thank you,
John-Paul
n/a Points
2014-12-04 12:08 pm

No John i don't want Domain.in mails to be hosted where Domain.co is!

I want Domain.in mails to be "AS THEY ARE" untouched, and just redirect/forward visitors from Domain.in to Domain.co (which is hosted on IMH and up-and-running as expected with separate mail server and everything)

Both domains are registered with Registrar1, Domain.in hosted with Registrar2, Domain.co hosted with InMotion.

I tried setting up domain forwarding on Registrar1 Domain.in to Domain.co but Domain.in is still displaying old contents of the website despite waiting for over 24 hrs. So, i don't think domain propagation is happening.

Does that clarify my question? 

Thanks,

Om

Staff
11,023 Points
2014-12-04 12:19 pm
Hello Om,

Thank you for contacting us. All the of the redirects described on this page will redirect domains, but not affect email.

I am happy to help, but will need some additional information, to help narrow down the issue.

What type of redirect are you setting up with Registrar1? Is it one of the ones explained above? Which one?

Thank you,
John-Paul
n/a Points
2014-12-04 12:37 pm

Nope actually i used the "Domain Forwarding" option on Registrar1 domain panel. Regsitrar2 panel sucks and I can't access .htaccess file over there, nor able to set a domain forwarding instruction from there either.

When i see domains under my Network Solutions account, it shows EMPTY, which is also baffling me out, and only landing page files are uploaded via FTP and the email is setup.

Now without touching Domain.in emails, can i somehow forward Domain.in to Domain.co so that if anybody visits Domain.in he/she sees contents of Domain.co (I'm not worried about any masking - 302 redirect will do)

Staff
11,023 Points
2014-12-04 1:20 pm
Hello Om,

I looked up both your domains, and they are both registered with Registar1. This is most likely why it is not listed with Registrar2, but is really just a guess.

There are several ways to accomplish this, but this is the most common way:
Add Domain.in to your cPanel as an Addon Domain.

Create the following MX record for Domain.in:
10 inbound.Domain.in.netsolmail.net

(This is what the domain is currently using.)

Then, create the .htaccess redirect rule as described above, for Domain.in.

Allow up to 24 hours for this update to propagate.

Finally, point Domain.in to the Nameservers for InMotion Hosting. Within 24 hours the domain will be redirected to your Domain.co website. Email should continue working, since we already set the MX records up previously.

Thank you,
John-Paul
n/a Points
2014-12-04 2:46 pm

Okay what i've done is changed Domain.in as the primary domain (just clarifying since we were using dummy domain Domain.com as primary domain) and Domain.co is anyway the add-on domain, and inside the cPanel i've set the redirect from Domain.in to Domain.co in IMH panel.

I've also updated MX records for Domain.in as you advised, and now i don't think i need to again do the .htaccess redirect since it's already taken care of. 

So, after leaving a gap of few hours, I think i should simply update the nameservers of Domain.in to NS.InmotionHosting.com and NS2.inmotionhosting.com 

Am i correct or still missing something here?

May i also request you to edit my comments and replace Domain with Domain, Registrar1 with Registrar 1, and Registrar2 with Registrar 2 because i don't want this to be publicly posted forever - just posted exact things to help you understand the exact problem.

Hope you'd understand :)

Staff
20,888 Points
2014-12-04 3:05 pm
Hello Om,

Yes, that sounds like your solution should work fine. This way the .in will display .co, but the MX records for .in should keep mail as it is. Once pointed to our name servers, then everything should work as you desire.

Kindest Regards,
Scott M
n/a Points
2014-12-04 6:28 pm

Thanks for the help - while domain.in is redirecting to domain.co we again have mail havoc - domain.in mais are bouncing.

When i saw on registrar a/c the MX entry was inbound.promizon.com.netsolmail.net

instead of inbound.domainname.com.netsolmail.net you had suggested - am i missing something?

Staff
11,023 Points
2014-12-04 7:08 pm
Hello Om,

Thanks for contacting us. At the time I looked up the MX records for the domain.in, it was:
10 inbound.Domain.in.netsolmail.net

Wherever the email is hosted, just use their specific MX record settings. If you are not sure what they should be, the email host should be able to provide them to you.

We are happy to help further, but will need to review the bounce messages to help narrow down the problem.

Also, our bounceback parser tool can help determine the cause of returned/bounced messages.

Thank you,
John-Paul
n/a Points
2014-12-04 7:07 pm

Upon bouncing I'm getting this error for mail delivery failure

This email is being returned to you because the remote server would notor could not accept the message. The registeredsite servers are justreporting to you what happened and are not the source of the problem.The address which was undeliverable is in the section labeled:  "----- The following addresses had permanent fatal errors -----".The reason your mail is being returned to you is in the section labeled:  "----- Transcript of Session Follows -----".

554 5.0.0 MX list for mail.ipixio.in points back to atl4mhib61.myregisteredsite.com554 5.3.5 Local configuration error

 

Final-Recipient: RFC822; abc@ipixio.inAction: failedStatus: 5.5.0Remote-MTA: DNS; mail.ipixio.inLast-Attempt-Date: Thu, 4 Dec 2014 17:24:02 -0500

Oops i forgot to ask if i should remove this from MX records, and in email routing should i select "automatically detect" or "local mail exchanger"

0

ipixio.in

 

Staff
11,023 Points
2014-12-05 11:01 am
Hello Om,

Thank you for contacting us. Your Email Routing setting for domain.in, should be set to Remote Mail Exchanger. Since the email is not handled on our servers.

Yes, you absolutely want to delete the following record:
0 domain.in

This will override all other MX entries, since the zero (0) record is used first, when attempting to deliver mail.

Thank you,
John-Paul
n/a Points
2014-12-06 7:24 am

Thank you so much for the post. Been looking for such a solution for a while since.

However, I did this:

RewriteCond %{HTTP_HOST} ^test.domain1.comRewriteRule ^(.*) http://test.primary1.com/$1 [P]

And it redirected without the URL changing.

But http://test.primary1.com has a login page, the moment I login, the url changes from test.domain1.com to http://test.primary1.com

Is there any more conditions that I ought to put to make it remain?

Thanks.

Staff
20,888 Points
2014-12-08 2:45 pm
Hello Dapo,

It is difficult to say right off hand. If you are using a CMS of some sort, they tend to have their own redirects and rewrites also involved. The .htaccess file is read from the top down, so there could be other rules involved as well.

Kindest Regards,
Scott M

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.

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