Mix static files into WordPress

Viko asked:

I’m migrating a previously-static site to WordPress 4.3.1. Most things are working fine, but I have one odd case: I need example.com/foo/ to be dynamic, but I need example.com/foo/bar/ to be static. I’ve created a /foo/bar/index.html to handle example.com/foo/bar/, but now example.com/foo/ is giving a 403 Forbidden code.

I also need example.com/foo/bar/ to show up in the menu, which I’ve accomplished by adding a dynamic example.com/foo/bar/ as well (deleting this doesn’t help).

The example.com/foo/ page still exists and can be edited in admin. Why am I getting 403 and how can I fix it?

My answer:

This happens because the WordPress Apache rewrite rules pass everything on to WordPress which does not exist as a file or a directory on the filesystem, which is what the two RewriteCond rules check for. But you do have a directory corresponding to /foo/ on the filesystem, causing Apache to handle it internally.

To resolve this, you’ll need to tell Apache explicitly to pass this on to WordPress (and do this with any other URLs that might have directories masking them from the first rewrite rule).

Add a new section of directives just before the end of the IfModule:

RewriteCond %{REQUEST_URI} "/foo/" [OR]
RewriteCond %{REQUEST_URI} "/bar/" [OR]
RewriteCond %{REQUEST_URI} "/baz/"
RewriteRule . /index.php [L]

As for the WordPress menu, you shouldn’t add blank pages to add entries to it. Instead, just create custom menu entries with the desired URLs to your static pages. Click on Custom Links in the menu editor and add the desired information.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.