Page 3 of 3
Re: Faster Page Loads with Subdomains for Images & Uploads
Posted: Thu Feb 11, 2010 3:19 pm
by kendo451
Ok, I think the simplest thing for me would be a Mod Rewrite line that will simply rewrite any/all subdomains to the root directory of the
www.domain.com
I will generate the proper subdomain in the url via CMSMS and my templates and stylesheets.
Unfortunately, writing mod_rewrite strings is not my forte.
What's the simple, reliable way to mod_rewrite all subdomains to the html root and keeping the same URI for the folder path and filename?
Ken
Re: Faster Page Loads with Subdomains for Images & Uploads
Posted: Thu Feb 11, 2010 3:33 pm
by kendo451
I decided to modify jeremy's original suggestion to rewrite all subdomains to the root, so I modified his .htaccess example so it doesn't exclude the www. subdomain. I want it to just rewrite all subdomains, including www, to root.
Code: Select all
# rewrite all subdomains to livingoffshore.com
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP_HOST} ([^.]+)\.livingoffshore.com
RewriteRule ^(.*)$ %1
I also created the following DNS records:
Code: Select all
css.livingoffshore.com. A 174.132.248.51
img.livingoffshore.com. A 174.132.248.51
js.livingoffshore.com. A 174.132.248.51
ul.livingoffshore.com. A 174.132.248.51
www.img.livingoffshore.com. A 174.132.248.51
Maybe I should have used CNAME records instead of A's?
It isn't working.
It is redirecting somewhere, but the server isn't hitting the files.
Re: Faster Page Loads with Subdomains for Images & Uploads
Posted: Thu Feb 11, 2010 3:46 pm
by JeremyBASS
FWIW... two things.. One, to handle the CSS and JS automagical.. try my mod Scriptdeploy... it is designed to work on subdomians with shared roots... two be careful with this kinda rewrite I have found you can get yourself in an infinite loop pretty fast... which is why I had two versions...
Re: Faster Page Loads with Subdomains for Images & Uploads
Posted: Thu Feb 11, 2010 3:50 pm
by kendo451
The "Scriptdeploy" mod Jeremy referenced above is here:
http://dev.cmsmadesimple.org/projects/scriptdeploy
Awesome module, Jeremy! I've just been poking around a little bit, and am quite impressed by the polish and attention to detail in the admin interface. I look forward to trying it out and reviewing it here.
Back to .htaccess. What I need is a simple .htaccess script that will do this:
rewrite
*.domain.com/foo or
*.*.domain.com/foo to
domain.com/foo
Example: img.domain.com/foo/bar.htm -> domain.com/foo/bar.htm
Example:
www.img.domain.com/foo/bar.htm -> domain.com/foo/bar.htm
Example:
www.domain.com/foo/bar.htm -> domain.com/foo/bar.htm
Here is a useful page that explains how to set up your DNS, your script and your .htaccess file:
http://www.easymodrewrite.com/example-subdomains
Re: Faster Page Loads with Subdomains for Images & Uploads
Posted: Thu Feb 11, 2010 4:20 pm
by JeremyBASS
why thanks... it's still being worked on so SVN is hot with change

...
So I'm wondering why the need for
Example:
www.img.domain.com/foo/bar.htm -> domain.com/foo/bar.htm
just wondering...
Re: Faster Page Loads with Subdomains for Images & Uploads
Posted: Thu Feb 11, 2010 4:44 pm
by kendo451
The reason for the need to rewrite
www.sub.domain.tld is that CMSMS image manager and file manager have a bug where they append
http://www. to the URL if it doesn't start with http://www.
I can fix this bug, but the fix will get overwritten next time I upgrade, so I will work around it instead. This way my sites will not break when future version of CMSMS does fix the bug.
If I want image and file manager uploads to be pulled from the subdomain, I have to use this hack, which was apparently invented by Gregor.
I set the image manager path to
http://www.img.domain.com/uploads/images
and the file uploads path to
http://www.ul.domain.com/uploads
And I will use mod rewrite to make those paths hit
http://domain.com/whatever
Re: Faster Page Loads with Subdomains for Images & Uploads
Posted: Thu Feb 11, 2010 4:58 pm
by JeremyBASS
Oh I see what your doing.. I bypass that with correcting the config file...
$config['root_url'] = 'http://' . $_SERVER['SERVER_NAME'];
so if a request comes in at www. that that is what it gets etc... I think that was all I did to over come that... hmm I think...
Re: Faster Page Loads with Subdomains for Images & Uploads
Posted: Thu Feb 18, 2010 3:52 am
by JeremyBASS
So in this area here is another little bit.. so one benefit to images on subdomains is no cookies.. but if you use Google Analytics it'll put a cookie on anyway... so I did a test... I used the ._setDomainName(); and I forced it to my www subdomain... with that you can stop cookies coming from the subdomain images without losing the tracking of you user. It also seems to speed of the js script since it's only process a part of what it was before.... (note I force users from domain.tld to
www.domain.tdl)
ex:
Code: Select all
<__script__ type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</__script>
<__script__ type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-xxxxxxxx-1");
pageTracker._setDomainName("www.domian.org");
pageTracker._trackPageview();
} catch(err) {}</__script>
Cheers
Jeremy