Redirect sub domains to sub folders

Discussion in 'Site & Server Administration' started by Blue DIamond STL, May 15, 2019.

  1. #1
    I am in the process of changing the architecture of a site from:

    subdomain1.domain.co.uk/product_a
    subdomain2.domain.co.uk/product_b
    subdomain3.domain.co.uk/product_c

    to:

    www.newdomain.co.uk/brand_a/product_a
    www.newdomain.co.uk/brand_b/product_b
    www.newdomain.co.uk/brand_c/product_c

    Basically, the subdomains are brand names, I have always hated the architecture so changing to a better subfolder system.

    When I go live I know I need to use .htaccess for my permanent redirections, but for the life of me I can't figure out how it's written, anyone any ideas?

    It's a WordPress/woo site.

    Thanks in advance
     
    Last edited by a moderator: May 15, 2019
    Blue DIamond STL, May 15, 2019 IP
  2. RoseHosting

    RoseHosting Well-Known Member

    Messages:
    230
    Likes Received:
    11
    Best Answers:
    11
    Trophy Points:
    138
    #2
    This will redirect subdomain1.domain.co.uk/product_a to www.newdomain.co.uk/brand_a/product_a


    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^subdomain1.domain.co.uk
    RewriteRule ^(.*)$ http://www.newdomain.co.uk/brand_a/$1 [L,NC,QSA]
    Code (markup):

    A more general rule if the subdomain and the subdirectory are sharing the same name:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(.*)\.domain\.co\.uk
    RewriteRule ^(.*)$ http://www.newdomain.co.uk/%1/$1 [L,NC,QSA]
    Code (markup):
     
    RoseHosting, May 26, 2019 IP