Search code examples
.htaccessmod-rewritehttp-redirectsubdomain

.htaccess subdomains redirect is not working


Ok, now I am lost.

I am trying to do a simple .htaccess redirect of subdomains to a specific folder on the server, meaning all

subdomain.mywebsite.com

will go to

www.mywebsite.com/s_subdomain

But for some reasons this doesn't work.

I have tried a lot of settings in .htaccess but for no good. Now in my .htaccess I have:

RewriteEngine on

Options +FollowSymLinks
Options +SymlinksIfOwnerMatch

RewriteCond %{HTTP_HOST} !^(www|ftp|mail)\.mywebsite\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.mywebsite\.com
RewriteRule (.*) /s_%1/$1 [L]

Are there any other settings, or is somethig I have missed?

PS. - I don't have access to http.conf. I have to do it using only .htaccess

Thanks!


Solution

  • This is just a "plain" rewrite (the browser won't see it). To redirect, add the R flag to your RewriteRule.

    RewriteRule (.*) /s_%1/$1 [L,R]
    

    The rest seems right, although I haven't tested it. For debugging you could consider RewriteLog, see http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritelog