Forums / Developer / Adding subdomains w/o setting or mod_rewrite manipulation

Adding subdomains w/o setting or mod_rewrite manipulation

Author Message

Piotrek Karaś

Wednesday 10 October 2007 10:52:47 am

Let's say we've got a one-class-based flat-structured catalog of items of whatever sort. The standard addressing for the full view of each node can be:
System:
<b>/content/view/full/[ITEM_ID]</b>
or
Virtual:
<b>/[WHATEVER]/[THE]/[ITEM_OBJECT_NAME]</b>

Would it be possible to add a unique subdomain for each item so that the full view is also accessible with that subdomain? But, of course, without having to configure anything (settings, .htaccess, mod_rewrite etc.) each time we add/edit/remove an item?

For example:
<b>subdomain1.domain.com</b> -> <b>/content/view/full/123</b>
<b>subdomain2.domain.com</b> -> <b>/content/view/full/5423</b>

Is it even possible with eZ Publish? Any ideas?
Thanks

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Betsy Gamrat

Thursday 11 October 2007 4:46:44 pm

Cool question! :)

I'd create a .conf file to include into the Apache .conf settings. This would probably have to be generated by an eZ extension, executed by runcronjobs.php.

The .conf file would have a VirtualHost directive like so:

<VirtualHost 127.0.0.1>
ServerName example.com
ServerAlias www.example.com
ServerAlias subdomain1.example.com
ServerAlias subdomain2.example.com
DocumentRoot /home/example/public_html/ez

... Standard rewrite rules ...

</VirtualHost>

I'd also append the siteaccesses into site.ini.append.php, like so:

MatchOrder=host
HostMatchMapItems[]=example.com;site_user
HostMatchMapItems[]=subdomain1.example.com;site_user
HostMatchMapItems[]=subdomain2.example.com;site_user
HostMatchMapItems[]=admin.example.com;site_admin

Resources:

http://httpd.apache.org/docs/1.3/misc/rewriteguide.html

Check "Extended Redirection" - you may be able to write the Perl code to perform the redirection with a script as part of your extension.

http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

Check "RewriteMap" - you may be able to effectively create an array.

Good luck!

Piotrek Karaś

Wednesday 17 October 2007 9:27:57 am

Thanks for your reply, Betsy. I will definitely give it a deeper look.

Meanwhile, I think I have come up with a solution that maybe will not stand a universal one, but may fit into our hosting environment configuration. Just in theory for now:

1) I configure my HTTP server so that a given domain and any user-dynamically-created subdomains of any level direct the root of the installation. That will probably require a wildcard of some kind. Lets say, I've got a <b>domain.com</b> domain and I setup a <b>*.domain.com</b> rule, meaning * can be anything.

2) I create a mod_rewrite rule which reads the requested SERVER_NAME and extracts (and validates/secures) whatever the subdomain part name is (if there is anything in place of <b>*</b>), and redirects to something like this:
<i>/domain.com/index.php/default_siteaccess/content/view/subdomain/(name)/*</i>
where * is whatever the subdomain was.

For example:
<i>letstry.domain.com</i> <b>is rewritten to</b> <i>/domain.com/index.php/mysite/content/view/subdomain/(name)/letstry</i>

3) Now it's easy to create a template override for a given class and for the mode "subdomain" of the view view of content module. I can easily grab the value of "name" parameter, and it all gets down to is a fetch in the template (a "subdomain" attribute in the class would be useful).

---

I still have to make this empirical, but I have good feelings about it ;)
Will get back to this issue ;)

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu