htaccess rewrite all domains to new domain

Hello,

I have 40 domains that point to one domain but they keep their domain names in tact, I want to change that.

Currently I have it so:
domain1.com
domain2.com
domain3.com

show their domain names but actually load
domain.com

I want the htacess to say
if domain.com then nothing, if not domain.com then change the domain name to domain.com and leave the other info in the url

ie
if domain1.com/search/test.php
then rewrite domain.com/search/test.php
LVL 1
movieprodwAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark BullockQA EngineerCommented:
Put this in the VirtualHost for each domain you want to redirect.
RewriteRule  ^/(.*)  http://domain.com/$1  [R,L]

Open in new window

0
movieprodwAuthor Commented:
what if they all use the same htacess, will that create a loop?
0
Mark BullockQA EngineerCommented:
No. You will not have this rewrite rule in the VirtualHost for domain.com.
0
Acronis Data Cloud 7.8 Enhances Cyber Protection

A closer look at five essential enhancements that benefit end-users and help MSPs take their cloud data protection business further.

movieprodwAuthor Commented:
Okay, but I don't have a vitualhost for them, they are just pointed by dns, so there is only one htacess file and one index.php file so I need to make it so if it is domain.com then great, if not then redirect to domain.com/xxxx
0
Mark BullockQA EngineerCommented:
You can add a rewrite condition.
RewriteCond %{HTTP_HOST} ^www.domain\d.com$
RewriteRule  ^/(.*)  http://domain.com/$1  [R,L]

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
movieprodwAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.