Forum Moderators: phranque
RewriteEngine on
RewriteCond %{HTTP_HOST}!^(www\.)?example\.com [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com [NC]
RewriteRule .* /beta/mi/showprofile.php?usershow=%1 [R=301,L]
Some of it is code based from here but some isn't. I need insite pretty much on what to do and would like to know what im doing, not just get the code.
Thanks.
#Be sure subdomain is not www
RewriteCond %{HTTP_HOST}!^www [NC]
#Extract the subdomain
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com [NC]
#Do internal rewrite from subdomain to script
RewriteRule ^$ /beta/mi/showprofile.php?usershow=%1 [L]
--------------
I'm afraid I can't do much more explaining due to my lack of understanding, but I was in the same boat as you a while back and this is what I finally got to work.
How exactly is this not working and, are you trying to redirect 'silently' and serve the information to the subdomain from the same domain, or redirect externally and send the browser to the main domain where the information is?
I ask, because it appears you would like to serve the information to the sub, but you are using a R=301, external flag, so I am not sure I understand.
The second question I have is where are you actually serving the information from, because there seems to be a conflict in this path:
example.com/mi/showprofile.php?usershow=this
And this path from your rule:
/beta/mi/showprofile.php?usershow=%1
RewriteEngine on
RewriteCond %{HTTP_HOST}!^(www\.)?example\.com [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com [NC]
RewriteRule .* /beta/mi/showprofile.php?usershow=%1 [R=301,L]
Overall, it looks like you are close though. I am sure someone will be able to help you get there soon.
One little adjustment I can suggest if you will be checking every file is to change the left side of your rule to:
RewriteRule . /
If you are not going to store the information in a variable, it is faster to just check and see if a character exists in the request than to process the entire request.
There is also a slight HTTP 1.0 client conflict, because they do not send HOST headers, but this can be corrected with:
RewriteCond %{HTTP_HOST} .
as the first condition. Of course this would then cause another conflict, because they will not be served the correct information since they are not redirected, but I'll let you decide on how to handle that, or maybe it can be addressed more fully later.
Hope this helps.
Justin
BTW {HTTP_HOST}!^ //means 'if the host in the http header is not...'
...there is something with CNAME in the DNS zone I have to edit.
That's probably the wildcard DNS he's talking about.
I'm not exactly sure what entry you need to make, but if you ask your host they'll probably do it for you.
Essentially what wildcard DNS is doing is putting an '*' in front of your domain name, allowing the server to accept anything instead of just www, mail, ftp, etc. If you don't have this entry it will just ignore all other subdomains.