This is a discussion on Wildcard subdmoains within the Apache Web Server forums, part of the Web Server and Related Forums category; "Rik" <luiheidsgoeroe@hotmail.com> schreef in bericht news:4f6cc$4581f4c2$8259c69c$28664@news1.tudelft.n l... &...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
"Rik" <luiheidsgoeroe@hotmail.com> schreef in bericht
news:4f6cc$4581f4c2$8259c69c$28664@news1.tudelft.n l... > HansH wrote: >>> RewriteEngine on >>> RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$ >>> RewriteRule ^/(.*)$ /$1/$2 >>> >> An untested thought ... >> RewriteRule ^/(.*)$ /%1/$1 [QSA,PT] >> >> Still, AFAIK only functional for those FQDN specified with servername >> or serveralias witin a common vhost. Found myself wrong on this ... missed some samples at http://httpd.apache.org/docs/2.0/vho...sed.html#using ServerName www.domain.tld ServerAlias domain.tld *.domain.tld > Well, the .htaccess rewrite is the simple bit. Let's say I have a > subdomain > subs.example.com, to which I wish to direct all 'unknown' subdomains: Only rewritemap ${MapName:LookupKey|DefaultValue } has a default. However rewritemap is not available in .htaccess. Feel free to test this # set default for unkown SetEnvIf site=subs # set for each known SetEnvIfNoCase Host www.domain.tld site=www SetEnvIfNoCase Host 123.domain.tld site=123 SetEnvIfNoCase Host xyz.domain.tld site=123 RewriteEngine on RewriteRule ^/(.*)$ /%{ENV:site}/$1 \ [QSA,PT,E=DOCUMENT_ROOT:%{DOCUMENT_ROOT}%{env:SITE}/] I've never used the 'E=... 'this way, might work, may fail... .... if it works, will give fully isolated subsites. HansH |
|
|||
|
HansH wrote:
> "Rik" <luiheidsgoeroe@hotmail.com> schreef in bericht > news:4f6cc$4581f4c2$8259c69c$28664@news1.tudelft.n l... >> HansH wrote: >>>> RewriteEngine on >>>> RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$ >>>> RewriteRule ^/(.*)$ /$1/$2 >>>> >>> An untested thought ... >>> RewriteRule ^/(.*)$ /%1/$1 [QSA,PT] >>> >>> Still, AFAIK only functional for those FQDN specified with >>> servername or serveralias witin a common vhost. > Found myself wrong on this ... missed some samples at > http://httpd.apache.org/docs/2.0/vho...sed.html#using > ServerName www.domain.tld > ServerAlias domain.tld *.domain.tld Yup, so: ServerName sub.example.com ServerAlias *.example.com Should work, no? >> Well, the .htaccess rewrite is the simple bit. Let's say I have a >> subdomain >> subs.example.com, to which I wish to direct all 'unknown' subdomains: > > Only rewritemap ${MapName:LookupKey|DefaultValue } has a default. > However rewritemap is not available in .htaccess. Indeed, but also this should not be needed. The 'random' subdomains should be redirected to sub.example.com. There is absolutely no need to try to use mod_rewrite for this, leet alone RewriteMap :-). > Feel free to test this > # set default for unkown > SetEnvIf site=subs > # set for each known > SetEnvIfNoCase Host www.domain.tld site=www > SetEnvIfNoCase Host 123.domain.tld site=123 > SetEnvIfNoCase Host xyz.domain.tld site=123 > > RewriteEngine on > RewriteRule ^/(.*)$ /%{ENV:site}/$1 \ > [QSA,PT,E=DOCUMENT_ROOT:%{DOCUMENT_ROOT}%{env:SITE}/] > > I've never used the 'E=... 'this way, might work, may fail... > ... if it works, will give fully isolated subsites. Well, isolated is not where I'm after. If that's what I wanted, I would just create subdomains explicitly, which is a lot simpler :-). I'm trying to take advantage of the wildcard, to have they 'internal' workings of a site exactly the same (page building, user logging, etc.), but the content all different from the database, based on the name of the subdomain. That way, I don't have to worry about creating subdomains, updating code on every single one, etc. -- Rik Wasmus |
|
|||
|
"Rik" <luiheidsgoeroe@hotmail.com> schreef in bericht
news:e303$45828b3a$8259c69c$17649@news2.tudelft.nl ... > HansH wrote: > Yup, so: > ServerName sub.example.com > ServerAlias *.example.com > Should work, no? Yes, it does for me with version 2.2.3. It is documented for 1.3 too ... .... somehow I've skipped that page for over 7 years in a row >> Only rewritemap ${MapName:LookupKey|DefaultValue } has a default. >> However rewritemap is not available in .htaccess. > Indeed, but also this should not be needed. > The 'random' subdomains should be redirected to sub.example.com. > There is absolutely no need to try to use mod_rewrite for this, The rewritemap would return 'Default Value' for LookupKeys not listed. Defaulting is part of your question and this single directive justs gets closest. > ... let alone RewriteMap :-). You cannt use rewritemap in .htaccess ... >> Feel free to test this >> # set default for unkown >> SetEnvIf site=subs >> # set for each known >> SetEnvIfNoCase Host www.domain.tld site=www >> SetEnvIfNoCase Host 123.domain.tld site=123 >> SetEnvIfNoCase Host xyz.domain.tld site=xyz >> >> RewriteEngine on >> RewriteRule ^/(.*)$ /%{ENV:site}/$1 \ >> [QSA,PT,E=DOCUMENT_ROOT:%{DOCUMENT_ROOT}%{env:SITE}/] >> >> I've never used the 'E=... 'this way, might work, may fail... >> ... if it works, will give fully isolated subsites. > > Well, isolated is not where I'm after. If that's what I wanted, I would > just create subdomains explicitly, which is a lot simpler :-). It is my understanding your hoster is providing you ONE WILDCARD domain on a shared host and you are attempting to virtualize that for some subdomains. > I'm trying to take advantage of the wildcard, to have the 'internal' > workings of a > site exactly the same (page building, user logging, etc.), but the content > all different from the database, based on the name of the subdomain. That > way, I don't have to worry about creating subdomains, updating code on > every single one, etc. Try RewriteRule ^/(.*)$ /yourscript.pqr?site=%{ENV:site}&request=$1 [QSA,PT] Even then isolation may come in handy for images, stylesheets and javasripts. To use a single script accros all subdomains have subs/pages/.htacces and www/pages/.htaccess rewrite the request to that script: RewriteRule ^.*/(.*)$ %{DOCUMENT_ROOT}/../yourscript.pqr?site=%{ENV:site}&request=$1 [QSA,PT] If your need to change, just modify one of the */pages/.htaccess to have that one sub domain use another script. HansH |
|
|||
|
HansH wrote:
> "Rik" <luiheidsgoeroe@hotmail.com> schreef in bericht > news:e303$45828b3a$8259c69c$17649@news2.tudelft.nl ... >> HansH wrote: >> Yup, so: >> ServerName sub.example.com >> ServerAlias *.example.com >> Should work, no? > Yes, it does for me with version 2.2.3. > It is documented for 1.3 too ... > ... somehow I've skipped that page for over 7 years in a row Well, as long as that works, my question is totally answered. >>> Only rewritemap ${MapName:LookupKey|DefaultValue } has a default. >>> However rewritemap is not available in .htaccess. >> Indeed, but also this should not be needed. >> The 'random' subdomains should be redirected to sub.example.com. >> There is absolutely no need to try to use mod_rewrite for this, > The rewritemap would return 'Default Value' for LookupKeys not listed. > Defaulting is part of your question and this single directive justs > gets closest. The only 'defaulting' that's needed is to arrive at the particular subdomain from a subdomain that's ot explicitly set, keeping the subdomain in the browser window as is. >> ... let alone RewriteMap :-). > You cannt use rewritemap in .htaccess ... I know, 't was a pain to write an alternative for toupper; without it some months ago. Don't ask me why I needed it.... Something to do with backwards compatibility with buggy code out of my control. >>> Feel free to test this >>> # set default for unkown >>> SetEnvIf site=subs >>> # set for each known >>> SetEnvIfNoCase Host www.domain.tld site=www >>> SetEnvIfNoCase Host 123.domain.tld site=123 >>> SetEnvIfNoCase Host xyz.domain.tld site=xyz >>> >>> RewriteEngine on >>> RewriteRule ^/(.*)$ /%{ENV:site}/$1 \ >>> [QSA,PT,E=DOCUMENT_ROOT:%{DOCUMENT_ROOT}%{env:SITE}/] >>> >>> I've never used the 'E=... 'this way, might work, may fail... >>> ... if it works, will give fully isolated subsites. >> >> Well, isolated is not where I'm after. If that's what I wanted, I >> would just create subdomains explicitly, which is a lot simpler :-). > It is my understanding your hoster is providing you ONE WILDCARD > domain on a shared host and you are attempting to virtualize that for > some subdomains. It is indeed a shared host, but all other subdomains are explicitly set. It's managed by Plesk, and in that configuration I can easily make new subdomains to my harts desire. I don't have access to the XML api though, and a project of mine requires the use of on the fly subdomains. The scripts in those subdomains remain the same, only the content extracted from the database and a single suitable named configuration file differ. Unfortunately, I offcourse don't get permission to examine their total configuration. I have to guess a lot :(. >> I'm trying to take advantage of the wildcard, to have the 'internal' >> workings of a >> site exactly the same (page building, user logging, etc.), but the >> content all different from the database, based on the name of the >> subdomain. That way, I don't have to worry about creating >> subdomains, updating code on every single one, etc. > Try > RewriteRule ^/(.*)$ /yourscript.pqr?site=%{ENV:site}&request=$1 > [QSA,PT] RewriteMap is unfortunately not an option, and furthermore not needed as this does same enough work as: RewriteCond %{HTTP_HOST} !^explicit_subdomain\.example\.com RewriteCond %{HTTP_HOST} !^([^.]+)\.example\.com RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^{.*}$ /myscript.php?site=%1&request=$1 [QSA,L] Wether a particular subdomain should or shouldn't exist is totally up to the furthet script, which is quite capable of that. I appreciate all suggestions about what to do with the request further on, but that's all unneccesary, and easily figured out. The main thing was the ServerAlias thing, and as far as I can gather, I was indeed right about it's workings, so I'll contact my hoster and let them explain in detail why they cannot ServerAlias to work (or maybe they can...). -- Rik Wasmus |
|
|||
|
Rik wrote:
> The main thing was the ServerAlias thing, and as far as I can gather, > I was indeed right about it's workings, so I'll contact my hoster and > let them explain in detail why they cannot ServerAlias to work (or > maybe they can...). And once again, I seem to be lacking in some communcation skill, even in my native tongue. It was a confusion in actual goal rather then a configuration problem. It is totally possible & now being configured, and all is well. Thanks for all your time. -- Rik Wasmus |
| Thread Tools | |
| Display Modes | |
|
|