Wildcard subdomain to file htaccess

Posted by Mikkel Larson on Server Fault See other posts from Server Fault or by Mikkel Larson
Published on 2013-06-27T10:10:28Z Indexed on 2013/06/27 10:22 UTC
Read the original article Hit count: 293

Filed under:
|
|

I've have a problem with a htaccess wildcard redirect

My base configuration is set to work with: www.domain.com and domain.com

this is governed by 2 .htaccess files:

1: /home/DOMAIN/public_html/.htaccess

AddDefaultCharset utf-8

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?festen.dk$  

RewriteCond %{REQUEST_URI} !^/public/ 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public/$1 

RewriteCond %{HTTP_HOST} ^(www.)?festen.dk$ 
RewriteRule ^(/)?$ public/index.php [L]

2: /home/DOMAIN/public_html/public/.htaccess

AddDefaultCharset utf-8
<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
</IfModule>

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Now i want to redirect: www.[SUBDOMAIN].domain.com/[PATH] and [SUBDOMAIN].domain.com/[PATH] to

public/index.php/subdomaincontroller/realsubdomain/[PATH]

My solution so far: Added following to 2: /home/DOMAIN/public_html/public/.htaccess

<IfModule mod_rewrite.c>
    RewriteCond %{HTTP_HOST} !www.domain.com$ [NC] 
    RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+)domain.com [NC] 
    RewriteRule (.*) subdomaincontroller/realsubdomain/%2/$1 [L] 
</IfModule>

Sadly this dows not work. Can anyone help me please?

© Server Fault or respective owner

Related posts about .htaccess

Related posts about subdomain