Forum Moderators: phranque
I'm new to the forum and desperately need help after searching the forum and not able to find solution to my problem.
What I'm trying to achive:
a. subdomain.example.com to be sent to a jsp page in Tomcat with subdomain as parameter
b. sub.domain.example.com to be sent to a jsp page in Tomcat with sub.domain as paramater (NOTICE the dot sub.domain)
b. sub.dom.ain.example.com to be sent to a jsp page in Tomcat with sub.dom.ain as paramater (NOTICE the dot sub.domain)
In otherwords, only example.com is fixed, whatever before that and doesn't matter how many dot involved, need to be considered as a single value/parameter when passing to the JSP
My problem:
- The RewriteCond (includede below) that I have only handles case (a) above (no dot at all in the subdomain)
This is what I have:
- Apache 2.2.4 + mod_jk + mod_rewrite + mod_vhost_alias
- Tomcat 5.5.17
- a working wildcard dns *.example.com
The VirtualHost in my httpd.conf currently looks like this:
[codes]
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
JkMount /foo/*.jsp ajp13w
RewriteEngine On
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^example\.com$
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z][a-z0-9_\-]{2,11})\.example\.com
RewriteRule ^/(.*)$ /foo/hello.jsp?name=%2 [PT]
</VirtualHost>
[/codes]
Can anyone help to suggest a better RewriteCond?
Thanks in advance!
Rgds,
Hendra
The only remaining problem is that the pattern in your third RewriteCond is too specific -- It will not match any strings with periods in them. So a nice, simple solution might be:
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)\.example\.com
RewriteRule ^/(.*)$ /foo/hello.jsp?name=%2 [PT,L]
RewriteRule ^/(.*)$ /foo/hello.jsp?name=%2[b]&page=$1[/b] [PT,L]