Page is a not externally linkable
- Code, Content, and Presentation
-- Apache Web Server
---- Htaccess Redirecting Questions


lucy24 - 2:37 am on Jan 22, 2013 (gmt 0)


i am looking for an htaccess that changes say subdomain.example.com/blah.html to a new url at example.com/blah.html but if possible the old subdomain index page which would be subdomain.example.com/psp to example.com/psp

Do all of your subdomains pass through the same htaccess? If so you have got it made because you will probably be able to delete about 90% of your current rules, leaving only the canonicalization rule. That's the one that goes (DO NOT cut & paste, I'm doing this off the top of my head)

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

The Condition will pick up anything that isn't your primary domain name in its canonical form-- including any and all subdomains. You have, or should have, some version of this rule in place already. All you've done now is erase any previous rules and/or conditions that pulled out the subdomains.

The immediately preceding rule already is-- or should be-- the one that grabs any request for explicit "index.html" (or whatever extension you use) and redirects to the directory alone.

I don't get the difference between "blah.html" and "psp". It seems to be the identical process.

All of this is assuming that every page on every subdomain has an exact match on the primary domain, so for every

subdomain.example.com/directory/foo.html
othersub.example.com/widgets.html
thirdsub.example.com/directory/subdirectory/

you already have a corresponding

www.example.com/directory/foo.html
www.example.com/widgets.html
www.example.com/directory/subdirectory/

If this is the case, I can see why you want to dump the subdomains ;)


Thread source:: http://www.webmasterworld.com/apache/4537934.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com