Follow

How to Configure Apache

Rewrite Rules

The Pugpig Module needs to rewrite URLs to create a usable content hierarchy for offline use. Out of the box, this is done using Drupal, which doesn't provide great performance for serving static files. You can use the following Apache mod_rewrite rules to improve performance:

You can place these rules immediately under RewriteEngine on in the ''.htaccess' file in the Drupal site root. You will need to restart Apache for the rules to take effect. You should notice a significant difference when serving static files, or when packaging the static file part of the edition.

Single Site

Note: The rules will need to be rather different if you are running Drupal Multisite. This assumes all assets in default files area.

Note: You cannot use these rules to accelerate protected content as the Drupal module needs to set headers which control access upstream.

Note: If your modules or themes are not installed at the root of the modules or themes directory, you will need to change the relevant rules.

Note: These rules might break if you allow certain characters into the URL (for example a % in the path). See section at bottom.

  RewriteEngine on
 
  # Pugpig Rewrite Rules - copy from here
 
  # Assets on an edition, for example the cover (with or without a style)
  # editions/issue858/assets/cover.jpg
  # editions/issue858/assets/styles/cover/public/cover.jpg
  RewriteRule ^editions/[^/]+/assets/(.*)$ sites/default/files/$1 [L]
 
  # Theme and module assets
  # Note: If the path to your theme/module is deeper, this might need to change
  # editions/issue858/data/themes/mytheme/images/123.png
  # editions/issue858/data/modules/mymodule/456.png
  RewriteRule ^editions/[^/]+/data/themes/([^/]+)/(.*)$ sites/all/themes/$1/$2 [L]
  RewriteRule ^editions/[^/]+/data/modules/([^/]+)/(.*)$ sites/all/modules/$1/$2 [L]
 
  # Assets on a node (with or without a style)
  # editions/issue858/data/5965/assets/123.jpg
  # editions/issue858/data/5965/assets/styles/ipad/public/123.jpg
  RewriteRule ^editions/[^/]+/data/[0-9]+/assets/(.*)$ sites/default/files/$1 [L]
 
  # Package XML file
  # editions/issue858/issue858-package-1334067161.xml HTTP/1.1
  RewriteRule ^editions/[^/]+/([^-]+)-package-([0-9]+).xml$ sites/default/files/pugpig/packages/$1-package-$2.xml [L]
 
  # Asset ZIP files
  # editions/issue858/issue858-assets-1334067161.zip HTTP/1.1
  RewriteRule ^editions/[^/]+/([^-]+)-assets-([0-9]+).zip$ sites/default/files/pugpig/packages/$1-assets-$2.zip [L]
 
  # HTML ZIP files
  # NOTE: You cannot use this if you have secure content as the module sets entitlement headers
  # editions/issue858/issue858-html-1334067161.zip HTTP/1.1
  # RewriteRule ^editions/[^/]+/([^-]+)-html-([0-9]+).zip$ sites/default/files/pugpig/packages/$1-html-$2.zip [L]
 
  # Ad Packages
  # editions/issue858/data/5881/ad_package/123.png
  RewriteRule ^editions/[^/]+/data/([0-9]+)/ad_package/(.*)$ sites/default/files/pugpig/ad_packages/$1/$2 [L]
 
  # End Pugpig Rewrite Rules  
 
  ... other existing rewrite config
  

 

Multi Site

Note: This assumes the site directory matches the domains. If this is not the case, you will need many custom rules 

Note: This will only work for theme and module assets in a specific site, not in the 'all' site

   
RewriteEngine on
 
  # Pugpig Rewrite Rules - copy from here
 
  # Assets on an edition, for example the cover (with or without a style)
  # editions/issue858/assets/cover.jpg
  # editions/issue858/assets/styles/cover/public/cover.jpg
  RewriteRule ^editions/[^/]+/assets/(.*)$ sites/%{HTTP_HOST}/files/$1 [L]
 
  # Theme assets
  # Note: If the path to your theme/module is deeper or you are using subthemes, this might need to change
  # editions/issue858/data/themes/mytheme/images/123.png
RewriteRule ^editions/[^/]+/data/themes/([^/]+)/(.*)$ sites/%{HTTP_HOST}/themes/$1/$2 [L]

# Module assets (not recommended to have any assets in the module!) # editions/issue858/data/modules/mymodule/456.png RewriteRule ^editions/[^/]+/data/modules/([^/]+)/(.*)$ sites/%{HTTP_HOST}/modules/$1/$2 [L] # Assets on a node (with or without a style) # editions/issue858/data/5965/assets/123.jpg # editions/issue858/data/5965/assets/styles/ipad/public/123.jpg RewriteRule ^editions/[^/]+/data/[0-9]+/assets/(.*)$ sites/%{HTTP_HOST}/files/$1 [L] # Package XML file # editions/issue858/issue858-package-1334067161.xml HTTP/1.1 RewriteRule ^editions/[^/]+/([^-]+)-package-([0-9]+).xml$ sites/%{HTTP_HOST}/files/pugpig/packages/$1-package-$2.xml [L] # Asset ZIP files # editions/issue858/issue858-assets-1334067161.zip HTTP/1.1 RewriteRule ^editions/[^/]+/([^-]+)-assets-([0-9]+).zip$ sites/%{HTTP_HOST}/files/pugpig/packages/$1-assets-$2.zip [L] # HTML ZIP files # NOTE: You cannot use this if you have secure content as the module sets entitlement headers # editions/issue858/issue858-html-1334067161.zip HTTP/1.1 # RewriteRule ^editions/[^/]+/([^-]+)-html-([0-9]+).zip$ sites/%{HTTP_HOST}/files/pugpig/packages/$1-html-$2.zip [L] # Ad Packages # editions/issue858/data/5881/ad_package/123.png RewriteRule ^editions/[^/]+/data/([0-9]+)/ad_package/(.*)$ sites/%{HTTP_HOST}/files/pugpig/ad_packages/$1/$2 [L] # End Pugpig Rewrite Rules

 

Tips and Tricks

You may need to escape certain characters, for example if you have a path with a % in the name such as: /Images/10% Discount/shirt.gif

# This directive cannot go into .htaccess. Put it elsewhere
RewriteMap escape int:escape
 
RewriteRule ^editions/[^/]+/data/[0-9]+/assets/(.*)$ sites/default/files/{escape:$1} [L]

 

If your domains do not exactly match your Drupal multisite site directories, you'll need to map to them. For example, if your public facing domains all have an extra api. in front, you'd need something like this on each rule:

RewriteCond %{HTTP_HOST} ^api.([^:]+)(:[0-9]+)?$ [NC]  
  RewriteRule ^editions/[^/]+/assets/(.*)$ sites/%1/files/$1 [L]

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Powered by Zendesk