Forum Moderators: phranque

Message Too Old, No Replies

.htaccess rewriting

use differents subdomain from only one location

         

bouquet92

11:15 am on Apr 4, 2006 (gmt 0)



Hello,

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

jdMorgan

2:51 pm on Apr 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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]

There are slightly-more-efficient ways to code this, but this approach does not scale well at all (image having thousands of customer-ids).

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]

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim