Forum Moderators: phranque

Message Too Old, No Replies

Excluding an addon domain from a rewrite.

         

Mikroz

9:40 am on Jan 6, 2011 (gmt 0)

10+ Year Member



Howdy all,

I've given this forum a challenge or two in the past and today I'm going to step it up a notch or three with my latest dilemma. Here are the details...

RewriteCond %{HTTP_HOST} !^((www\.)?one\.co\.za\.?(:[0-9]+)?)?$
RewriteCond %{HTTP_HOST} !^((www\.)?two\.za\.net\.?(:[0-9]+)?)?$
RewriteCond %{HTTP_HOST} !^((www\.)?three\.za\.org\.?(:[0-9]+)?)?$
RewriteCond %{HTTP_HOST} !^((www\.)?four\.za\.org\.?(:[0-9]+)?)?$

# Exclude folders
RewriteCond %{REQUEST_URI} !^/(_email)/

# Exclude phpinfo.php, sitemap.xml and robots.txt
RewriteCond $1 !^(phpinfo\.php|sitemap\.xml|robots\.txt)$

# Externally redirect all other requests to "sub.example.com"
RewriteRule ^(.*)$ http://sub.example.com/$1 [R=301,L]


Here's what's going on with that horror...

'one' is an addon domain. It's actively in use.
'two' is an PARKED domain. It's not in use and is simply going to a placeholder page located in the root.
'three' is an addon domain. It's actively in use.
'four' is a PARKED domain. It's about to be used...

There are redirect exclusions for certain files and for a certain folder: 'email'.

Everything else is then redirected to 'sub.example.com'.

The problem now is that I want to redirect 'four' to a location on an existing 'site and keep its URL intact.

ie: 'four.za.org' reflects 'four.za.org' in the address bar and loads 'blah.example.com/lorem/ipsum/' as the content.

At the moment it is redirecting to 'sub.example.com' and nothing I try has fixed this as yet.

What am I missing and where is it missing?

I've tried adding code before, in and after the above bundle. It either redirects to 'sub' or to the general placeholder page that 'two' shows.

Any suggestions would be most welcome and appreciated.

Thanks, Nic

jdMorgan

5:56 pm on Jan 7, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Exclude the example.za.org requests from the "catch-all" redirect by using a negative-match RewriteCond based on the %{HTTP_HOST}, just as coded with "one.example.za.org" etc. in the first rule.

You may then want/need to add another, separate, canonicalization rule for example.za.org -- that is, if requests for that host are excluded from the catch-all, you might want to add another rule to redirect requests for www.example.za.org or example.www.za.org to the canonical example.za.org, since many users tend to want to type spurious "www"s on everything, and it would be better to 'land' them on the correct host in that case. Certainly you'll want to get the current problem fixed before proceeding to that, though.

Jim

Mikroz

7:33 pm on Jan 12, 2011 (gmt 0)

10+ Year Member



Thanks for the reply jdMorgan - and apologies for my delayed response.

I understood the first part of your reply but got lost with the second.

I've been doing a lot of reading and have come to the understood conclusion that what I want to do is not possible, despite the 'sites being hosted on the same server.

I changed the parked domain to an addon one and got it to show the content I wanted from the other domain but failed at keeping the 'four.za.org' in the address bar.

Thanks, Nic

jdMorgan

5:37 pm on Jan 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The second part of my reply mentioned an "optional" and "nice-to-have" function, but implementing it or not implementing it would have no effect on the success or failure of the basic function you're trying to implement.

I was simply saying that you need an exclusion for your last rule, which you should actually list as your second rule:

# Externally redirect all other requests to "sub.example.com", except for "example.za.org"
RewriteCond %{HTTP_HOST} !^(www\.)?example\.za\.org
RewriteRule ^(.*)$ http://sub.example.com/$1 [R=301,L]

Jim

Mikroz

7:02 pm on Jan 14, 2011 (gmt 0)

10+ Year Member



Hi Jim,

Thanks for explanation and example - I'm now following you 100%. :)

So I was more or less on the right track but I had the order of rules incorrect.

I learn more about .htaccess all the time.

I also like to conjure up ridiculously complex rules sometimes, but it does eventually result in me learning a new lesson or two every time. Hehe.

Cheers, Nic