What is it?
You may occasionally run into issues where some elements of your site aren’t loading over the desired URLs. This can happen when making changes such as adding CDN support or enabling SSL protection on your site. This is a common issue on hosting platforms, but one that we’ve been able to combat with a simple but powerful custom utility called HTML Post-Processing. This utility is commonly used by our support staff to solve issues of this nature, however it is also fully accessible from within your WP-Admin dashboard!
How do I access and use it?
HTML Post-Processing is part of our mu-plugin, which means it is enabled by default on all installs on our platform. You can access it by heading to the WP Engine section of your WP-Admin panel on your install hosted with us. Once on that page, you want to scroll to the bottom and find the HTML Post-Processing section, as shown below:
The tool is able to find and replace values based on either literal strings or PHP Regular Expressions (RegEx) or a combination of both. You can enter one find-replace rule per line, using the following general format:
#match# => replace
We have included some examples of possible usage below:
Force all references loaded over HTTP to serve via HTTPS for the specified domain:
#http://domain.com# => https://domain.com
Load all uploads files from CDN
#domain.com/wp-content/uploads# => ZONE.wpengine.netdna-cdn.com/wp-content/uploads
Force HTTPS on a custom CDN domain for wp-content/uploads
#https?://domain.com/wp-content/uploads# => https://cdn.domain.com/wp-content/uploads
Force HTTPS on a CDN Zone Url for static content and references
#https?://(www.)?(INSTALL.wpengine.com|DOMAIN.COM|ZONEID.wpengine.netdna-(cdn|ssl).com)/wp-(content|includes)# => https://ZONEID-wpengine.netdna-ssl.com/wp-$4
Exclude a single file from CDN
#https?://ZONE.wpengine.netdna-cdn.com/(wp-content/themes/theme)/retina.js# => http://domain.com/$1/retina.js
Caveats and Things to Consider
Please note that the above rules are not guaranteed to work on all installs and in all situations. This tool is extremely powerful, however there are still things that it can conflict with based on other site configurations. We do have some additional tips for proper usage:
- You want to be sure to always “escape” all RegEx metacharacters in the source of the rule, though the destination of your rule does not need to have these characters escaped.
- It’s recommended that you double-check the rules for any potential spelling mistakes before saving.
- These rules can negatively affect third party resources if a domain is not specified in the Post-Processing rule, so you want to always be specific!
- Post-Processing does not affect the staging environment at all.
While HTML Post-Processing is a powerful tool that can help with URL replacements on the fly, it is definitely always recommended that these fixes be implemented in your site’s code in the long run. Ideally, this tool should be considered a band-aid that merely allows a site to work while a developer creates a long-term solution.
As always, if you have any questions or concerns, your WP Engine Support staff is available to help 24/7/365.