Forum Moderators: phranque
I'm under apache 1.3 (linux) and i would like to use several subdomain but with only one place where i saved my php files:
for example i would like to use following sub domain
Toto.mydomain.com
Titi .mydomain.com
Tutu.mydomain.com
and when i use the url [toto.mydomaine.com...] in fact it go to execute (transparent not redirect) to [toto.mydomaine.com...] for titi or 13 for toto .. (with indeed different .htaccess).
Could you help me please to find the correct syntax for an .htaccess file please to do that?
Best regards,
Philippe
Welcome to WebmasterWorld!
The direct answer is that you'd have to handle it case-by-case, since toto does not directly imply "12" and titi does not directly imply "13":
RewriteCond %{HTTP_HOST} ^toto\.example\.com
RewriteRule (.*) /test.php?idcust=12 [L]
#
RewriteCond %{HTTP_HOST} ^titi\.example\.com
RewriteRule (.*) /test.php?idcust=13 [L]
A better approach would be to rewrite *any* subdomain other than "www" to test.php, and then let test.php open a database of customer names and the customer id associated with that name. Although mod_rewrite used in the server context (httpd.conf or conf.d) does implement a database lookup function (See RewriteMap), a PHP solution would be far more flexible.
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule (.*) /test.php?idcust=12 [L]
Jim