tags:

views:

130

answers:

1

I am trying to redirect http://[random-string].domain.com/ to http://domain.com/folder/[random-string]/

I currently have this:

RewriteCond %{HTTP_HOST} ^.*\.domain\.com
RewriteRule ^.*$ http://domain.com/folder/$1/ [R=301,L]

It currently points to http://domain.com/folder//. (The $1 is missing) How do I fix this?

A: 

You need to use parenthesis to grab the value matched, in your case:

RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com
RewriteRule ^(.*)$ http://domain.com/folder/%1/$1 [R=301,L]

assuming you also want to redirect http://[random-string].domain.com/something to http://domain.com/folder/[random-string]/something

gregseth
Hm, the $1 variable is still missing. (It redirects to http://domain.com/folder//)
Yongho
Ok my bad, see the edit to my answer (use % instead of $ for RewrtieCond)
gregseth