0

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Well done +1 for you... maybe QSA flag at the end of the RewriteRule (it all depends what aroma wants to do)
The query string gets appended automatically when a ? isn't present in the rule's target. If the rule's target was /users/%1/files/$1?redir=no or something, it would need a QSA.
I know, but suppose that some other URLs which have parameters after their '?' pass through this rules: their parameters are lost. So it all depends of what aroma wants to do: either be sure to drop all the parameters before and apply only then new ones, or keep the old ones and mix with the new ones.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.