View Single Post
Old 03-04-2008, 01:30 PM   #5 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Since we're afforded the yumminess that is regular expressions, we can simply specify that the trailing slash is optional with the question mark character (?). Also, will the varying values only ever be numbers? Or, would you like to only capture what's between sample/ and the next forward slash (if there is one)? I'm just asking because it's better to make the matching expression as specific as possible! At the moment sample/my/sub/domain.html would try to redirect to http://my/sub/domain.html.domain.com which I'm fairly sure you don't want.

Anyhow, to answer your question:
RewriteRule ^sample/(.*)/? http://$1.domain.com [R=301,L]
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
Dan (03-04-2008)