-1

this is my first question on ServerFault and I think I couldn't find a similar one.

To the point. I would like to achieve the following using my .htaccess.

subdomaina.example.com/stats/ -> subdomaina.example.com/subdomaina/stats/
subdomainb.example.com/stats/ -> subdomainb.example.com/subdomainb/stats/
subdomainc.example.com/stats/ -> subdomainc.example.com/subdomainc/stats/

Subdomaina,b,c and test.com need to be dynamic and not static.

I know that I should be using the mod-rewrite but I am a bit confused.

I quite unexperienced with apache and .htaccess, so any pointers, clues, and explanation is greatly appreciated.

1 Answers1

4

To solve problems like this, you should read and become familiar with the mod_rewrite documentation, especially the mod_rewrite reference and regular expressions.

This example is easy enough:

RewriteEngine on
RewriteCond %{HTTP_HOST} (.*)\.example\.com$
RewriteRule ^/stats/(.*) /%1/stats/$1 [R]