Forum Moderators: phranque

Message Too Old, No Replies

How to redirect only one site when multiple are on the same hosting

         

trezcan

5:56 pm on Sep 13, 2012 (gmt 0)

10+ Year Member



I added a new domain to my hosting account (site3.com) and put it in a subdirectory. Unfortunately, I cannot access the site now because it 301s to another site automatically.

Here are the details:

- site1.com moved urls to site2.com. Everything has been working fine.
- .htaccess for site1.com is in the root directory, controlling the redirect to site2.com.
- site2.com is all in its own subdirectory
- I recently added site3.com and put it in its own subdirectory
- Now site3.com forwards to site2.com (lands on a search page looking for the domain name "www.site2.com/?search=site3")

I spoke with my hosting company today and they said the htaccess file in the root controlling to redirect from site1.com to site2.com is set to forward all domains to site2.com. They said I need to write it specifically so it only forwards site1.com. That will prevent me from having this issue every time I add a new site to the hosting account. Unfortunately, they do not offer support for that and wouldn't tell me how.

My question is can I edit the htaccess file in the root directory to only redirect site1.com to site2.com? Here is what I have right now in the htaccess file:

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.site2.com/$1 [R=301,L]

trezcan

6:24 pm on Sep 13, 2012 (gmt 0)

10+ Year Member



So I found what appears to be a work around. Apparently site3.com did not have an .htaccess file in its subdirectory so I just added one. This seems to work, but is this the best fix?

I would prefer to only have the root level .htaccess file forward site1.com to site2.com.

trezcan

7:42 pm on Sep 13, 2012 (gmt 0)

10+ Year Member



The quick fix I mentioned above worked for about an hour, now it is redirecting to site2.com. Scratch that off the list of fixes.

lucy24

9:28 pm on Sep 13, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



htaccess rules work on all domains unless there is a RewriteCond looking at the {HTTP_HOST}. So redirects will pick up all requests for all domains and send them all to the same place. And rewrites simply can't be done unless you have the exact same pattern in all domains.

It's generally safer to have only one htaccess file, but if you have multiple domains in a single userspace, you are probably better off with a separate one in each domain. Details will depend on your exact (physical) configuration; mine goes like this:

userspace
--htaccess file containing only universal information: in my case, core Allow/Deny directives and ErrorDocument statements that don't use domain names
--domain 1
-- --files for domain 1
-- --htaccess file containing material that's specific to domain 1, including ALL redirects (mod_rewrite only) and also "Options -Indexes" because it won't work in the shared file
--domain 2
-- --files for domain 2
-- --htaccess file as above

There's a little bit of duplication between the two lower htaccess files-- things like fake referer blocks-- but not a lot, since it's generally filename-specific.