Roots Theme Rewrites & WPEngine

Getting Roots theme rewrites and clean asset URLs working on WPEngine.

  • The Roots WordPress theme's Rewrites feature (clean URLs for static theme assets) requires nginx rewrite rules to work properly on WPEngine.
  • WPEngine doesn't provide access to nginx.conf, so you must use its Redirect Rules feature instead.
  • Setup is simple: log in at my.wpengine.com and go to the Redirect Rules screen.
  • Add an 'Assets' rule for All Domains with source ^/assets/(img|js|css|fonts)/(.*)$ and destination /wp-content/themes/roots/assets/$1/$2.
  • Add a second rule for All Domains with source ^/plugins/(.*)$ and destination /wp-content/plugins/$1.
  • This approach can also be used generally to set up custom nginx-style redirects and rewrites (similar to location and try_files) on WPEngine.

The Roots theme for WordPress is awesome, and so is WPEngine. When using the two together you’ll need to configure nginx rewrite rules to get the Rewrites (clean URLs for static theme assets) feature working properly.
WPEngine doesn’t give you access to an nginx.conf file, so you’ll need to use WPEngine’s Redirect Rules feature to configure these redirects. Luckily, it’s very simple to do.

Manage Rewrite Rules on WPEngine

  1. Login in to your WPEngine account at my.wpengine.com
  2. Browse to the Redirect Rules screen
  3. Add the following redirect rules

Rewrite for /assets/

  • Redirect Name: Assets
  • Domain: All Domains
  • Source: ^/assets/(img|js|css|fonts)/(.*)$
  • Destination: /wp-content/themes/roots/assets/$1/$2

Rewrite for /plugins/

  • Redirect Name: Assets
  • Domain: All Domains
  • Source: ^/plugins/(.*)$
  • Destination: /wp-content/plugins/$1

As a side note, this can be used in general to setup custom nginx redirects and rewrites, similar to location and try_files, on WPEngine.

Resume