views:

37

answers:

1

Hello,

I'm trying to create a .htaccess that would for a subdomain "test" redirects all requests this way:

http://test.mydomain.com/something/something2             (1)

to

http://test.mydomain.com/www/something/something2         (2)

so that in browser's address bar is still the address (1)?

I have Apache 2.0.

I'm trying to write it for two hours and I can't still find the right way.

Thanks!

+1  A: 

You'll want something like this:

RewriteEngine On

# Only redirect if we're on the subdomain and haven't redirected
# (internally) to /www/ yet
RewriteCond %{HTTP_HOST}    ^test
RewriteCond %{REQUEST_URI} !^/www/
RewriteRule ^.*$ /www/$0 [L]

# Let's also prevent them from being able to go to our /www path manually
RewriteCond %{THE_REQUEST}  ^(POST|GET)\s/www
RewriteRule ^www/?(.*)$ http://test.mydomain.com/$1 [R,L]
Tim Stone