views:

21

answers:

1

I want to make my .htaccess file do this:

From: http://www.domain.com/example  
-OR-  http://domain.com/example  
To:   http://example.domain.com  

and

From: http://www.domain.com/example/newfolder/file.html?q=blank  
-OR-  http://domain.com/example/newfolder/file.html?q=blank  
To:   http://example.domain.com/newfolder/file.html?q=blank  

For the life of me, I have searched and searched, and just can't figure it out.

+1  A: 

Try this rule:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^([^/.]+)(/.*)?$ http://$1.example.com$2 [L,R=301]
Gumbo
would this go in root or the example subdirectory?
Theo
@Theo: This is intended to be used in the .htaccess file in your document root directory. But don’t forget the obligatory `RewriteEngine on`.
Gumbo