Rewrite from subdomain to subfolder

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 4
Joined: 21 Jun 2016, 16:40

Rewrite from subdomain to subfolder

21 Jun 2016, 16:48

We currently have a set up that works and we are splitting things up via subdomain.

www.xyz.com
br.xyz.com
ca.xyz.com

similarily on product pages we have:

www.xyz.com/product-page.asp
br.xyz.com/product-page.asp
ca.xyz.com/product-page.asp

We then have a rewrite that goes like this:

RewriteRule product$ /product-page.asp [NC,L,QSA]

what I want to do is take the existing subdomain and re-write it as a subfolder and so hence if after the re-write above, someone where to visit:

www.xyz.com/br/product

They would get the same result as visiting: br.xyz.com/product


So hence all three of these would produce the same result

br.xyz.com/product-page.asp
br.xyz.com/product
www.xyz.com/br/product

Can anyone please help me with this... I have the following but it doesnt seem to work:

RewriteRule ^br/(.*)$ http://br.xyz.com/(.*) [NC,L,QSA]

User avatar
Posts: 4
Joined: 21 Jun 2016, 16:40

Re: Rewrite from subdomain to subfolder

21 Jun 2016, 17:38

As an alternative, I thought I could do something such as:

RewriteRule ^/(.*)/$ /(.*) [NC,L,QSA]

Then I was going to look for the first 4 letters in the query and do something accordingly as such it would be

http://www.xyz.com/br/somepage

This would essentailly trandlaste to http://www.xyz.com/somepage

However I would grab the /*whatevercountry*/ (subfolder) and show the appropriate content but this method doesnt seem to work either.

User avatar
Posts: 402
Joined: 06 Mar 2012, 11:59

Re: Rewrite from subdomain to subfolder

30 Jun 2016, 07:43

Hello.

To tell exact syntax I need to see your complete .htaccess, however, please try this rule:

Code: Select all
RewriteCond %{HTTP_HOST} (?!www\.)(\w+)\.xyz\.com [NC]
RewriteRule (.*) /%1/$1

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 19 guests