SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    520
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Redirecting after move from subfolder to subdomain -- how?

    My site consists of several distinct but closely related subsites. So far, they've been accessed via www.domain.com/Subsite1/, www.domain.com/Subsite2/, etc.

    I am now in the process of doing an overhaul of the design and of some of the structure, and it was suggested to me that we move to subdomains, so subsite1.domain.com, subsite2.domain.com, etc.

    I have considered this in the past, but I am of course concerned about breaking links all over the place. I don't think I have too much in the way of relative links internally, so it shouldn't be too hard to edit internal links ... but for external links, is it possible to have some kind of catch-all rewrite for each subsite?

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    LA,

    The direction you're going, all you need to do is to create the subdirectories (cPanel or httpd-vhosts.conf - make their DocumentRoot their own subdirectories) then, BECAUSE all the subdirectory links MUST go through the main domain, only one .htaccess redirect would be required:
    Code:
    RewriteEngine on
    RewriteRule ^(sub1|sub2|subx)/(.*)$ http://$1.domain/$2 [R=301,L]
    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    520
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not quite following what you mean by "make their DocumentRoot their own subdirectories"?

    The subdirectories are already there right now, since that's how the different sites are accessed today. But should they be moved, or is just httpd-vhosts.conf used to set each as a root directory? I don't have commercial hosting, so I don't have cPanel access or httpd-vhosts.conf access, but is that what I should tell my host to do then?

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    Linda,

    Hmmm, they don't give you much control, do they?

    When subdomains are setup, they're setup as domains and have their own DocumentRoot. Instead of pointing at the domain's DocumentRoot, they should point at the subdirectory of domain's DocumentRoot for their own - it's a whole new physical address.

    Some hosts merely redirect subdomains to the main domain's subdirectory (the URL changes to the main domain, too) and, if your host is one of those, you're out of luck.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #5
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    520
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I don't have much control to do things myself, but I can usually ask my host to setup things for me. So I think she would be fine with setting up each subdomain with its own DocumentRoot. In fact, she already has some "true" subdomains setup for me, so I imagine it won't be an issue at all.

    And if I get that done, all I need to use is the rewrite you described? That sounds great, thank you.

    My only other concern would be that I already have some pretty complex rewrites in my .htaccess that I had help putting together to simplify URLs for the CMS I use (mainly removing the index.php file from the URLs).

    For example:

    Code:
    RewriteRule ^/?GoT/((Index|Characters|Episodes|Features|Gallery|News)(/.*)?)$ /GoT/index.php/$1 [L]
    This is a rewrite so that urls like http://www.westeros.org/GoT/Features/ get rewritten for the system as http://www.westeros.org/GoT/index.php/Features/

    If I setup a got.westeros.org subdomain and add the rewrite you mentioned, how would I change this rewrite?

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    Linda,

    Put the subdomain redirections BEFORE the others (that will "get rid of" those URIs from later consideration as those requests would bypass the domain's .htaccess entirely) and not worry about any interference.

    UNLESS GoT is a subdomain in which case you'll need to move that mod_rewrite code to the NEW DocumentRoot for GoT.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  7. #7
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    520
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, GoT will be one of the subdomains.

    In that scenario, would that mean that I need:

    Code:
    RewriteRule ^(got)/(.*)$ http://$1.domain/$2 [R=301,L]
    in the .htaccess for the main (www) domain and

    Code:
    RewriteRule ^/?((Index|Characters|Episodes|Features|Gallery|News)(/.*)?)$ /index.php/$1 [L]
    in the .htaccess for the GoT subdomain?

    Do subdomains inherit anything from the .htaccess for the main domain, or does all necessary .htaccess code have to be repeated for each subdomains .htaccess?

  8. #8
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    Linda,

    Subdomains are domains within their own right. They can be hosted on completely different servers and have their own life apart from the main domain, i.e., they inherit NOTHING but the domain.tld from the main domain.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  9. #9
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    520
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, thank you. I think I'll be able to get this sorted out with my host from here.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •