Forum Moderators: phranque
My dns i set to:
*.example.com CNAME example.com
I've read that i should use A-name instead, but I don't know the IP, and i don't know if it changes, thats why i use CNAME, instead.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !www.example.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).example.com [NC]
RewriteRule (.*) $1 [L]
But this is what i get:
For www.sub.example.com an Error 400
And for sub.example.com an Error 500
To see whats wrong and what happens i tried to put in [R,L] insted of just [L] in the code above.
But then i get:
For www.sub.example.com an Error 400
And for sub.example.com an eternal redirect loop
Can you see what I'm doing wrong?
Thank you
[edited by: Grethe at 8:39 pm (utc) on Nov. 25, 2008]
RewriteEngine on
#
RewriteCond $1 !^sub_
RewriteCond %{HTTP_HOST} !www\.example\.com [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9\-]+)\.example\.com
RewriteRule (.*) /sub_%2/$1 [L]
I strongly suggest that you reject subdomains with uppercase characters in them, to avoid the resulting confusion from getting a 404 error that reveals the subdomain-subdirectory name in the path. I removed the [NC] from the second RewriteCond for that reason.
You should redirect to canonicalize the main domain and subdomains before doing the internal rewrite, so as to avoid both that problem and duplicate-content problems arising from FQDN-format hostnames, appended port numbers, case errors, extra or missing "www's", etc.
Jim