boy_v
boy_v

Reputation: 627

How can i set .htaccess for redirect subdomain to directory

How can i set .htaccess for redirect subdomain to directory

I have php backend and generate root directory same by username when user created

ex. php backend create user xxx my server create /var/www/html/xxx

this process it's completely abc.com/xxx i have done it.

but...

I want to redirect subdomain to directory

subdomain is dynamically from user

xxx.abc.com it's must redirect to abc.com/xxx

how can i set htaccess to do that

Upvotes: 1

Views: 47

Answers (1)

anubhava
anubhava

Reputation: 785126

You may use this rule in site root .htaccess:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.(abc\.com)$ [NC]
RewriteRule ^ http://%2/%1%{REQUEST_URI} [L,R=301,NE]

Upvotes: 2

Related Questions