Associate domain with website folder

Discussion in 'Installation/Configuration' started by Jemt, Oct 17, 2015.

  1. Jemt

    Jemt Member HowtoForge Supporter

    Hi,

    I have a lot of websites running on the same domain, e.g.
    http://domain.com/
    http://domain.com/sites/blog
    http://domain.com/sites/shop
    http://domain.com/sites/project-X, project-Y, project-Z, etc.

    All websites run on the same system, allowing me to quickly create new subsites, and upgrade all sites at once, by simply upgrading the CMS for the primary website (http://domain.com/).

    I now need to be able to associate domains with several of these sites, e.g.
    http://some-very-cool-web-shop.com => http://domain.com/sites/shop

    What I need is a "real domain", not just a redirect.

    What are my options ?

    - Thanks in advance : )

    Best regards
    Jimmy Thomsen
     
  2. splitter

    splitter New Member

    why is a redirect not an option? you can have a redirect but keep the url you want in the url bar, which will probably be the easiest solution.
     
  3. Jemt

    Jemt Member HowtoForge Supporter

    Splitter: No, a redirect will not let you keep the original URL at the address bar. URL Rewriting would allow something like it, but not across domains.

    What I need is being able to "map" a folder from accout X to a domain on accout Y.
     
  4. webguyz

    webguyz Active Member HowtoForge Supporter

  5. splitter

    splitter New Member

    Jemt: if mod_proxy is enabled, you should be able to do it with htaccess...
    i'll give an example in the next post (forum won't let me post the example because it thinks it contains links and i don't have enough posts...
    which is what you get for being a lurker :)
     
  6. splitter

    splitter New Member

    say you have: domain.top with your shops: domain.top/shop/one and domain.top/shop/two
    say that you are going to use example.org for shop one and foo.bar for shop two

    step 1: put all your domains in the same vhost (ie: servername domain.top, serveralias example.org, serveralias foo.bar)
    step 2: create the htaccess (next post *sigh*)
    step 3: done

    now, if someone goes to domain.top they stay there, if they go to domain.top/shop/one, they go to shop one,
    if they go to example.org/product they will end up on domain.top/shop/one/product BUT see example.org/product in the address bar,
    and same for foo.bar and shop 2.

    things to take into account:
    - your absolute/relative links have to be adapted for this scenario (using absolute links for foo.bar will end up changing the address bar, and using relative links is easy to break so pay attention)
    - you have to have mod_proxy enabled and all domains in one vhost
    - if the [L,NE,P] doesn't work, you might try [P,NC,QSA]
     
  7. splitter

    splitter New Member

    the htaccess;
    Options +FollowSymLinks -MultiViews
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^(www\.)?example\.org$ [NC]
    RewriteRule ^ http://www.domain.top/shop/one%{REQUEST_URI} [L,NE,P]
    RewriteCond %{HTTP_HOST} ^(www\.)?foo\.bar$ [NC]
    RewriteRule ^ http://www.domain.top/shop/two%{REQUEST_URI} [L,NE,P]

    keep in mind there might be an error in it, i'm a bit rusty :) - but i should have been more accurate since it's a rewrite and not a redirect, so technically... yeah, redirects won't do what you want. but it is possible in htaccess.
    another approach might be php, making an index page and having that extract information to just require the right things?
     

Share This Page