Forum Moderators: phranque

Message Too Old, No Replies

Redirect with Multiple Domains

Redirect multiple domain names to certain folders

         

o0Corps0o

1:10 pm on Jun 23, 2011 (gmt 0)

10+ Year Member



Hi,

I am currently trying to set up our .htaccess so that when a domain is entered into the address bar (eg. www.example.org) it would go to a folder (eg. www.example.org/folder).

The problem i am having with what i have at the moment is i think looping, so hence not working. I was thinking something along these lines:

RewriteCond %{HTTP_HOST} ^www\.example\.org$
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^index\.php$ http://www.example.org/folder [L]

or:

RewriteCond %{HTTP_HOST} ^www\.example\.org$
RewriteRule ^index\.php$ http://www.example.org/folder [L]

i'm searching for possible options, so if anyone could shed some light it would be appreciated.

Thanks.
Andy

wilderness

2:00 pm on Jun 23, 2011 (gmt 0)

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



more than 1,700 results "multiple+domains [google.com]"

o0Corps0o

10:14 am on Jun 24, 2011 (gmt 0)

10+ Year Member



Thanks for the results.. I just can't seem to get my head around it (i guess it doesnt help that we're using joomla so everything is index.php based and have JoomSEF installed)

Anyway, we have this working:

RewriteCond %{HTTP_HOST} ^www\.HONGKONG\.org$
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^index\.php$ [MAINSITE.org...] [L]

Which points to the correct page. But what we would like is to have the last line be something like:

RewriteRule ^index\.php$ [HONGKONG.org...] [L]

But it doesn't seem to like it...

(If Host == HONGKONG && folder == NULL) Then HONGKONG.ORG/HONGKONG
(If Host == HONGKONG && folder == string) Then HONGKONG.ORG/string

if that makes sense? (rather pointing to MAINSITE) so basically keeping HONGKONG in the address bar..

wilderness

2:25 pm on Jun 24, 2011 (gmt 0)

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



Excerpt Forum Charter [webmasterworld.com]

Please do not post specific details such as domain names, full IP addresses, or personally-identifiable information such as name, e-mail address, IM screen name, etc. Such specifics will be edited or removed in accordance with our Terms of Service [webmasterworld.com], which may render your post meaningless. Please replace all instances of your domain name with "example.com" before posting.

o0Corps0o

3:59 pm on Jun 24, 2011 (gmt 0)

10+ Year Member



Sorry, these were meant to be example domains... i do not own them, i was just trying to give a picture of how its not working...

wilderness

4:13 pm on Jun 24, 2011 (gmt 0)

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



The forun has a filter which converts the syntax on a live domain name to links, thus NEGATING your intention of providing exposure to the htaccess syntax.

That was my primary reason for the FYI.

the use of "example.com" for the domain name does NOT convert the syntax.

Try in a retype and you'll see!

o0Corps0o

8:47 am on Jun 27, 2011 (gmt 0)

10+ Year Member



Ok try again :) , we have this working:

RewriteCond %{HTTP_HOST} ^www\.example\.org$
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^index\.php$ mainsite/examplepage [L]

Which points to the correct page. But what we would like is to have the last line be something like:

RewriteRule ^index\.php$ example.org/examplepage [L]

But it doesn't seem to like it...

(If Host == Example && folder == NULL) Then Example.ORG/examplepage
(If Host == Example && folder == string) Then Example.ORG/string

lucy24

3:03 pm on Jun 27, 2011 (gmt 0)

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



Are "mainsite" and "example.org" different domains? If so you need to put in the complete version in the Rule:

http://www.example.org/ et cetera

If everything is happening within the same domain, you don't need to say anything about the HTTP_HOST at all. When you say QUERY_STRING do you mean query (the bit after the question mark in an address) or do you actually mean REQUEST_URI (the part after the domain name: either index.whatever or a longer address)?

o0Corps0o

8:51 am on Jun 28, 2011 (gmt 0)

10+ Year Member



mainsite.org and example.org are two different domains, but they reside on the same server and are pointing to the same things.

the problem I seem to have is looping. so if i put in the address bar: www.example.org then i would want it to point to www.example.org/folder but because of the way its written here i think its looping because it looks at example.org then redirects to example.org/folder which then reads in again as example.org and redirects again, etc etc..

lucy24

6:54 pm on Jun 28, 2011 (gmt 0)

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



Yup. That's when you cross your fingers and hope your server has stuck with the maximum-redirects = 10 so it stops before everything melts down. Or that you have a smart browser. (Firefox apparently checks.)

You need to exclude those cases where example.org is already followed by /folder. The basic ways (these are concepts, not cut & paste) are:

example.org AND NOT example.org/folder

and

example.org(?!/folder)

That is, either two conditions, or one condition with a lookahead.