Forum Moderators: phranque
Problem: this creates a situation where one page shows under several different URLs (addon domains are seen as SUBdomains, etc)
I can't quite figure out the right .htaccess code to fix this.
- Running Apache 2.2.8 (Unix), CPanel
* EXAMPLE: You register and use ONE.Com as your Primary LOGON domain... and set up a page.
You then have the ADDON Domains TWO.Com and THREE.com, use them to create other sites.
TWO .com will show up as THREE URLS-
[two.com...] (WHICH WE WANT)
BUT ALSO
[two.one.com...]
AND
[one.com...]
* I can fix the 2nd one, with a .htaccess 404 redirect in ONE.com's .htaccess, like so
RewriteEngine on
RewriteCond %{HTTP_HOST} ^two.one.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.two.one.com$
RewriteRule ^(.*)$ [one.com...] [R=301,L]
* BUT
I'm STILL stuck with:
[one.com...]
Duplicating my "two" page.
* I also tried clearing the above code from ONE.com, and using this in TWO.com's htaccess
RewriteCond %{HTTP_HOST} !^two.com$
RewriteRule ^(.*)$ [two.com...] [R=301,L]
* BUT
That doesn't work either.
[two.com...]
RESOLVES TO
[two.com...]
[one.com...]
RESOLVES TO
[two.com...]
AND:
[one.com...]
RESOLVES TO
[two.com...]
(Others show as 404, or Can't Locate Server)
- I wouldn't mind having ALL those show 404's, since they aren't "real" pages.
Or, if they DO redirect, it should be to the SAME root domain (ie, one.com/two should redirect to one.com etc).
- IDEAS?
Thanks in advance, for any help.
* I can fix the 2nd one, with a .htaccess 404 redirect in ONE.com's .htaccess, like so
RewriteEngine on
RewriteCond %{HTTP_HOST} ^two.one.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.two.one.com$
RewriteRule ^(.*)$ http://one.com/404.shtml [R=301,L]
That is not a 404, that is a 301-Moved Permanently redirect to http://one.com/404.shtml. This will result in the content of http://one.com/404.shtml being indexed under *any and all* possible two.one.com URLs -- A rather large duplicate-content problem.
There are also several syntax problems and inefficiencies, and one design error.
The correct way to generate a 404 in this case would be:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?two\.one\.com
RewriteRule (.*) /path_to_a_file_that_does_not_exist.html [L]
However, a better solution is to 301-redirect each subdirectory-subdomain, if and only if it is directly-requested by a client (e.g. browser or robot), back to the proper canonical subdomain root.
I'm also showing the fix for the simpler two.one.com case as the second rule here. It does not require the complex solution needed for the one.com/two/ case.
In one.com/two/.htaccess:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /two/
RewriteRule ^(.*)$ http://two.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?two\.one\.com
RewriteRule (.*) http://two.com/$1 [R=301,L]
GET /two/index.php HTTP/1.1
This is a typical HTTP request as logged (in quotes) in your raw server access log. The pattern I used above will match any valid HTTP request -- GET, HEAD, POST, etc.
In order to avoid potentially-devastating errors such as the "non-404" problem, I suggest you always test your redirect implementations with a server headers checker, such as the "Live HTTP Headers" add-on for Firefox and Mozilla browsers.
Jim
- I Put THIS in my .htaccess subdirectory for my "ADDON DOMAIN 2"
# In one.com/two/.htaccess:
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /two/
RewriteRule ^(.*)$ [two.com...] [R=301,L]
BUT, it makes me redirect to the WRONG domain.
(Anything with "one.com" in it, should redirect to one.com -- or pop a 404)
I tried changing RewriteRule to "one.com" -- but it caused other problems.
- This one I couldn't get to work, period
# In one.com/.htaccess:
RewriteCond %{HTTP_HOST} ^(www\.)?two\.one\.com
RewriteRule (.*) [two.com...] [R=301,L]
I put that into my MAIN LOGON Domain's .htaccess
It looked like this (with different URL data, of course):
RewriteCond %{HTTP_HOST} ^(www\.)?mywebsitedomain\.google\.com
RewriteRule (.*) [google.com...] [R=301,L]
- This had no effect on directing [mywebsitedomain.google.com...] to google.com
(I obviously don't run Google, but, you know what I mean.)
* I haven't downloaded FF's "LIVE HTTP HEADERS" yet -- too busy with this, but thanks for the tip. I'm going to get it now.
- The following works for me -- in all situations, except for
one.two.com - which generates a "Server Not Found" Error (Should I be concerned? Have I created an "index-able" URL?)
THIS IS WHAT I DID
# I put THS, in my MAIN LOGON .htaccess
Redirect 301 /two [one.com...]
And THIS, in my ADDON domain .htaccess
# Mod Rewrite sub.maindomain.com to subdomain.com
RewriteCond %{HTTP_HOST} ^two.one.com$ [NC]
RewriteRule ^(.*)$ [one.com...] [R=301,L]
-- How badly did I screw up?