http://www.webmasterworld.com Welcome to WebmasterWorld Guest from 38.103.63.62
register, login, search, glossary, subscribe, help, library, PubCon, announcements , recent posts, unanswered posts
Subscribe and Support WebmasterWorld
Home / Forums Index / The Webmaster World / Apache Web Server
Forum Library : Charter : Moderators: jdMorgan

Apache Web Server

  
Switching from subdirectory to subdomain.
Linda_A


#:3270542
 9:39 am on Mar. 4, 2007 (utc 0)

I am considering switching some subsections of my website to subdomains instead of just subdirectories to shorten the URLs. What is the easiest way of going about this?

My host suggested that she can setup the subdomains to have the current subdirectories as their root.

However, www.example.com/site1/ will still stop working, won't it? Is it possible to redirect all incoming requests to www.example.com/site1/<any page> to site1.domain.com/<any page>?

jdMorgan


#:3271566
 3:54 pm on Mar. 5, 2007 (utc 0)

Yes, and you will likely need to do both:

Externally redirect example.com/subdir/.* to subdir.example.com/.*
-and-
Internally rewrite subdir.example.com/.* to example.com/subdir/.*

The first steps "moves" your pages in the search engine listings, while the second step (or your host's suggested method) provides for the subdomain content's filesystem location.

Both of these functions can be implemented using mod_rewrite, which gives you control (independent of your host) over how the subdomain-to-subdirectory mapping is accomplished.

Note that there is a trick to implementing the above functions without creating an 'infinite' rewrite/redirection loop; You must check the server variable %{THE_REQUEST} in a RewriteCond to qualify the external redirection.

Jim

Linda_A


#:3286615
 7:13 pm on Mar. 19, 2007 (utc 0)

Darn, for some reason I never got an emailed notification of the response, despite checking the box. A belated thank-you. :)

I am not very familiar at all with mod_rewrite, do you have any examples of what the external and internal rewrites would look like?

What would you suggest, btw, as far as handling the internal rewrite? Is it better to use the method you suggest, or to have the host set it up? If I use the method you suggest, does my host even have to do anything at all to setup subdomains?

jdMorgan


#:3287548
 7:24 pm on Mar. 20, 2007 (utc 0)

This subject has been fairly well-covered here, so I'd recommend a site search on "subdomain subdirectory rewritecond HTTP_HOST rewriterule" to start. Then post specific questions here.

If you elect to have the hosting company install the rewrite for you, or if you use a "control panel" to do it, then you won't be able centrally-manage your subdomain->subdirectory rewrites; Part of the code will be in httpd.conf --only accessible indirectly through the control panel or by asking the host to change it-- and part of the code will be in your main domain's .htaccess file. That's the only compelling argument I can make for the .htaccess approach.

Jim

 

Home / Forums Index / The Webmaster World / Apache Web Server
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
WebmasterWorld ® and PubCon ® are a Registered Trademarks of WebmasterWorld Inc.
© WebmasterWorld Inc. / SearchEngineWorld 1996-2008 all rights reserved