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

eZ debug

Timing: Jan 20 2025 23:41:37
Script start
Timing: Jan 20 2025 23:41:37
Module start 'content'
Timing: Jan 20 2025 23:41:37
Module end 'content'
Timing: Jan 20 2025 23:41:37
Script end

Main resources:

Total runtime0.2215 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0071 589.5859180.7969
Module start 'content' 0.00710.0049 770.382897.9766
Module end 'content' 0.01200.2094 868.3594527.4219
Script end 0.2214  1,395.7813 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00391.7667200.0002
Check MTime0.00160.7108200.0001
Mysql Total
Database connection0.00080.350410.0008
Mysqli_queries0.174378.70431410.0012
Looping result0.00140.64191390.0000
Template Total0.209094.410.2090
Template load0.00090.402710.0009
Template processing0.208193.950910.2081
Override
Cache load0.00060.276710.0006
Sytem overhead
Fetch class attribute can translate value0.00160.717910.0016
XML
Image XML parsing0.00030.135410.0003
General
dbfile0.00401.8097200.0002
String conversion0.00000.002730.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs