Advertisement
Guest User

Example wordpress cdn rewrite

a guest
Dec 14th, 2011
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: CDN Rewrite
  4. Plugin URI: http://blog.andrewshell.org/cdnrewrite
  5. Description: Rewrite urls on page if behind a CDN
  6. Author: Andrew Shell
  7. Version: 1.0.0
  8. Author URI: http://blog.andrewshell.org/
  9. */
  10.  
  11. if (0 == strcmp($_SERVER['HTTP_USER_AGENT'], 'Amazon CloudFront')) {
  12.   $now     = time();
  13.   $expires = strtotime('+1 hour', $now);
  14.   header("Expires: " . gmdate(DATE_RSS,$expires) . "\n");
  15.  
  16.   add_filter( 'home_url', 'cdnrewrite_url', 100, 4 );
  17.   add_filter( 'site_url', 'cdnrewrite_url', 100, 4 );
  18. }
  19.  
  20. function cdnrewrite_url( $url, $path, $orig_scheme, $blog_id )
  21. {
  22.   return str_replace('blog.andrewshell.org', 'd11b8ym2xu437t.cloudfront.net', $url);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement