WPEngine, Nginx and htaccess

Redirects can get hairy sometimes – sometimes you get a nice clean canvas of directives, sometimes it’s messy and undocumented. Whatever the case, you’re dealing with an .htaccess file. One wrong move and you can crash your site
or worse yet a clients site. So before anything else make sure you have FTP access and you create a back up of their existing .htaccess file. Don’t even be tempted to do it through Yoast – even though they allow you to edit the .htaccess file right through WordPress. I’ve seen it happen and it isn’t worth it.

So you’ve got the .htaccess file – you’re going down line by line. It can look like a jungle at times – you’ll see caching stuff, some 301 redirects, some permission stuff.

With the task I got though, I simply had to redirect a .pdf file to an external domain. So you know how it goes, it could look something like this:

This is the mod_rewrite version


RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/old/path/file.pdf$
RewriteRule ^(.*) /new/path/file.pdf [L,R=301]

And the mod_alias version


Redirect 301 /old/path/file.pdf /new/path/file.pdf

Use either one and you’re all good and gravy – not unless you’re using WPEngine. I like this service, I actually recommend this to people looking for a user friendly platform to work with when building a wordpress site for their business.

So I was stumped for while – a long while actually. Why weren’t these directives working? Well come to find out after checking in with the guys and gals over there at WPEngine, that files were being served up and cached by Nginx. Nginx is another web server just like Apache. I don’t have much in depth knowledge of Nginx to be honest.

Here’s the information the tech provided:

Might be because static files are cached and served by nginx above apache. You should be able to use our redirect rules section in the user portal and that should work.

Alright to redirect any file formatted url – .pdf, .html, .aspx, .doc, etc, redirects had to be added using WPEngine.

Login in to your WPEngine account and through the dashboard, find “Redirect Rules” and here we can the necessary redirects.