Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I want to write a rewrite scheme such that:

user1.example.net will redirect to example.net/user/user1 user2.example.net will redirect to example.net/user/user2

vise versa

this is what i have in my .htaccess code. but it always redirects to example.net

RewriteCond %{http_host} ^[^.]+.example.net [NC] RewriteRule ^([^.]+).example.net(.*) http://example.net/user/$1 [R=301,L]

can someone please tell me what i did wrong? thank you.

share|improve this question

1 Answer 1

up vote 0 down vote accepted
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.example.com [NC]
RewriteRule ^(.*)$ http://example.com/user/%1/$1 [R=301,L]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.