pilotstarmedia.com
pilotstarmedia.com

Reputation: 577

mod-rewrite subdomain to subdomain dir

I have a bit of a problem with rewrite rules; so what I am trying to do is this;

[name].domain.com/files/ to [name].domain.com/users/[name]/files,

where [name] is sub-domain name, for instance "nick". Important part is that redirection should happened, only, if request contains sub-directory; files/.

Examples I could find on Google are examples related to sub-domain to sub-directory redirection and sub-directory to other sub-directory redirection, never combination of those two.

Upvotes: 0

Views: 164

Answers (1)

Jon Lin
Jon Lin

Reputation: 143856

Try putting these rules in the .htaccess file in your document root:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.  [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$  [NC]
RewriteRule ^files/(.*)$ /users/%1/files/$1  [L]

I assumed that you didn't have a www in your /users/ so I added the !^www\. condition. If you do want requests for www.domain.com to go to /users/www/ then just remove that line.

Upvotes: 2

Related Questions