Ákos Nikházy
Ákos Nikházy

Reputation: 1306

Folder to subdomain

My server provider stopped give me possible way to create subdomains in control panel and they say I should solve it with htaccess.

So I have to do something like this. When user types http://asdf.example.com it should get the content of http://example.com/asdf (as the provider changed even the FTP's structure... how kind of them)

I don't find any tutorial for this. Thanks in advance.

Upvotes: 0

Views: 238

Answers (3)

Gerben
Gerben

Reputation: 16825

More generic version of TerryE's answer. I haven't tested it though!!!

RewriteCond %{HTTP_HOST} !www.example.com
RewriteCond %{HTTP_HOST} (.*).example.com
RewriteCond %1/$0        !^([^/]+)/\1
RewriteRule ^.*          %1/$0   [L]

Upvotes: 2

TerryE
TerryE

Reputation: 10878

You don't need mod proxy. Just do an internal redirect:

RewriteEngine on
RewriteBase   /
RewriteCond   %{HTTP_HOST} =asdf.example.com
RewriteCond   $0           !^asdf/
RewriteRule   ^.*          asdf/$0             [L]

The rule rewrite the request prefixing asdf/ but only if (1) the host is http:/asdf... and (2) the rewrite hasn't already taken place. You need (2) to prevent iterative loops. $0 is the match string in the rule.

Hope this helps.

Upvotes: 1

Wouter Dorgelo
Wouter Dorgelo

Reputation: 11978

You can do that with mod_rewrite and mod_proxy:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^asdf\.example\.com$
RewriteRule ^ http://example.com/asdf%{REQUEST_URI} [L,P]

Upvotes: 1

Related Questions