1

As the title says, looking for the best way to integrate a cdn with EE.

I currently have a cdn account with MaxCDN and my solutions was to change the site_url within the configuration site to my cname address http://cdn.mysite.com.

From there I added a global variable and named it {root_url} that was my sites original address http://www.mysite.com.

Then just went and changed all menu links and such to use the global variable instead of the {site_url}.

This does work, however where I'm running into problems is the pagination. The pagination uses the site_url, which is now the cdn.

How are other people using a cdn with their EE install? Is there a better solution? Although this works, it seems clunky to me. Would really like to get some others advice/perspective.

I've been able to relate previous and next entries as well when viewing a blog post for example using this:

<ul class="pager">
  {exp:channel:prev_entry channel="blog"}
  <li class="previous">
    <a href="{root_url}blog/view/{url_title}">&larr; {title}</a></a>
  </li>
  {/exp:channel:prev_entry}
  {exp:channel:next_entry channel="blog"}
  <li class="next">
    <a href="{root_url}blog/view/{url_title}">{title} &rarr;</a> 
  </li>
  {/exp:channel:next_entry}
</ul>

But I've not been able to figure out how to change the pagination links to use the same {root_url} prefix. It seems you can completely customize the output and look of the pagination but not the links?

  • Why not leave the site_url as the actual site url and the create a global variable called "cdn_url" then use {cdn_url} in your templates when you need to call stuff from the CDN? – Justin Long Sep 16 '13 at 5:55
  • To me, this seemed more tedious. Because then I have to go in and change all js/css/images, instead of just the links and pagination. I guess it's just a matter of opinion though. Either is really as much of a pain. Would just like a cleaner solution. Also when using plugins such as CE image, changing root_url is an easy way to get all images cached too. – shparkison Sep 16 '13 at 20:57
2

So I figured it out by "hacking" the Pagination library in the CodeIgnitor core.

Upside: it works

Downside: need to re-apply hack after EE updates

If someone knows of a better solution I'd love to know!! Especially being as I'm a novice in PHP I don't know if this is the preferred way to accomplish this. With that said, here's what I did to overwrite the pagination URL's when using a CDN address for the {site_url}

Go to system > codeignitor > system > libraries > Pagination.php

Then on lines 242 - 254 (on version 2.4.0 of EE anyway) you would replace this:

if ($this->CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
{
    $this->base_url = rtrim($this->base_url).'&amp;'.$this->query_string_segment.'=';
}
else
{
    $this->base_url = rtrim($this->base_url, '/') .'/';
}

// And here we go...
$link_array = array();

$first_url = ($this->first_url == '') ? $this->base_url : $this->first_url;

With this:

if ($this->CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
{
    $this->base_url = str_replace("cdn","www",(rtrim($this->base_url).'&amp;'.$this->query_string_segment.'='));
}
else
{
    $this->base_url = str_replace("cdn","www",(rtrim($this->base_url, '/') .'/'));
}

// And here we go...
$link_array = array();

$first_url = str_replace("cdn","www",(($this->first_url == '') ? $this->base_url : $this->first_url));
| improve this answer | |
1

Have you tried the paginate_base parameter? You should be able to override the URL through this.

| improve this answer | |
  • I did not know about that parameter? Will definitely look into that. Thanks! – shparkison Sep 16 '13 at 20:57
  • Hope it works - it was a secret surprise for me once too. BTW, if it works, please mark the question as being answered.. ;) – Holland Sep 17 '13 at 10:30
  • Wow! been a while since I checked this, didn't have time to get back to this until now but the paginate_base="" doesn't do the trick. Still loads the {site_url} then appends whatever you put into paginate_base="" – shparkison Nov 25 '13 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.