Forum Moderators: phranque

Message Too Old, No Replies

Trying to redirect with parked domains with .htaccess

Trying to redirect with parked domains

         

BooGiE_MaN

1:14 pm on Oct 17, 2007 (gmt 0)

10+ Year Member



Here is what we have:

www.domain1.com
www.domain2.co.za (parked)
www.domain3.co.za (parked)

The site is split into two (eg. one for guys, one for girls)
www.domain1.com/home.php = site 1
www.domain1.com/site2/ = site2

I want if ppl go to www.domain2.co.za to go to www.domain2.co.za/site2/
and if people go to www.domain1.com to go to www.domain1.com/home.php

So far I've done some htaccess for preventing duplicate content:

RewriteCond %{HTTP_HOST} ^domain2.co.za [nc]
RewriteRule (.*) http://www.domain2.co.za/$1 [R=301,L]

#####

RewriteCond %{HTTP_HOST} ^domain1.com [nc]
RewriteRule (.*) http://www.domain1.com/$1 [R=301,L]

#####

RewriteCond %{HTTP_HOST} ^domain3.co.za [nc]
RewriteRule (.*) http://www.domain1.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.domain3.co.za [nc]
RewriteRule (.*) http://www.domain1.com/$1 [R=301,L]

Thanks in advance!

[edited by: jatar_k at 1:25 pm (utc) on Oct. 17, 2007]
[edit reason] delinked [/edit]

jdMorgan

5:00 pm on Oct 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please post the code you've experimented with as a basis for discuassion.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

g1smd

10:56 pm on Oct 17, 2007 (gmt 0)

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



Should this just work for the root, or does it need to be site-wide?

Which URL do you want the user to see in their browser?

What URL is on the page, in the clickable link?

BooGiE_MaN

11:05 pm on Oct 17, 2007 (gmt 0)

10+ Year Member



hi gsm1d

Currently you go to domain1.com/ its a splash page:
> Click here to go to site 1 (/home.php)
> Click here to go to site 2 (/site2/)

The domain has 2 parked domains
site1.com being the parent
site1.co.za meant to take people to the same place
and now site2.co.za which i want to take people to /site2/

Should this just work for the root, or does it need to be site-wide?

Which URL do you want the user to see in their browser?

It must be site-wide and there will be two possible urls showing:
site1.com (not .co.za as the .com is more established in search engines) and now also site2.co.za

Hope this makes more sense?

Main priority is to first get site2.co.za to go to site2.co.za/site2/
After I can get that right i'd like to try get site1.co.za/ and site1.com to go to site1.com/home.php

Thanks

[edited by: BooGiE_MaN at 11:14 pm (utc) on Oct. 17, 2007]

BooGiE_MaN

11:10 pm on Oct 17, 2007 (gmt 0)

10+ Year Member



Hi Jim

I'd dome some experimenting but ended up with 500 errors endlessly, hence looking for some guidance on htaccess here.
In PHP you can go if.. and.. or.. else.., but I dont know how that works with
RewriteCond
RewriteRule
since you can only have one condition.

jdMorgan

12:06 am on Oct 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And therein lies a tale... It doesn't matter if your code works, but discussing something that both you and we can see makes things a lot easier -- We can see where you are in terms of understanding mod_rewrite, for example. and don't have to repeat *all* the basics -- or tell you to go read the manual...

A RewriteRule can have as many RewriteConds as you like.

An else clause is implemented by ending the rule with an [L] flag. If the rule executes, then nothing after it will be executed. If the RewriteConds or RewriteRule conditions are not met, then that rule will not execute, the [L] flag will not stop rule processing, and the following rule will be evaluated, thus yielding the "Else" construct.

There are some limits and constraints on the boolean combinations you can construct using the default AND between RewriteConds, the optional [OR] specified with a flag on the RewriteCond(s), the "¦" local OR inside regular-expressions patterns, and the "[^]" character-group-negation and "!" pattern-negation operators, but generally, any function you can explain in concise comments can be implemented -- Or can be further broken down so that it can implemented.

Jim

BooGiE_MaN

9:36 am on Oct 18, 2007 (gmt 0)

10+ Year Member



Hi Jim

How can I use AND?
ie

RewriteCond %{HTTP_HOST} ^www.domain2.co.za (*AND*) %{REQUEST_URI}!www.domain2.co.za/site2

... I only want to redirect if the url is exactly www.domain2.co.za, not www.domain2.co.za/anythingatall

[edited by: BooGiE_MaN at 9:38 am (utc) on Oct. 18, 2007]

jdMorgan

12:47 pm on Oct 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



AND is the default operator if two or more RewriteConds are used and you do not add an [OR] flag to specify otherwise.

Do not mix-up the 'parts' of the URL; The HTTP_HOST variable contains only the 'domain' and an optional appended port number, while REQUEST_URI contains only the local URL-path. REQUEST_URI does not include the domain or any query string data appended to the requested URL-path.

Something like this is probably what you're looking for:


RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.co\.za
RewriteCond %{REQUEST_URI} !^/site2
RewriteRule (.*) http://www.domain1.co.za/site2/$1 [R=301,L]

However, I should warn you that this is an external redirect, and will 'expose' the domain1/site2 URL to your domain2 visitors. As such, it's not the best way to do this. Depending on how your DNS and host are configured, you might do better using an internal rewrite or a proxy throughput. I would recommend simply hosting domain2 properly as a better long-term solution; With today's competitive shared virtual server hosting fees as low as they are, any site that won't pay its own hosting bill usually isn't worth maintaining.

Jim