There are times when you’ll want to load a subdirectory in a WordPress setup decoupled from the WordPress core taxonomy handler (ie. a secondary non-wordpress app).

By default, when you try to load the subdirectory in a browser you’ll see a 404 “page not found” response – or a WordPress page that closely resembles the name of the subdirectory. This is because WordPress grabs the request for anything after a forward slash (domain.com/subdirectory) and assumes its should serve content from it’s own PHP.

Subdirectory .htaccess rules

We can do it in .htaccess. I’ve even gone ahead and made a sweet generator for you. Just type the name of the subdirectory below and click Generate. The page will reload and your fresh rules will spit out.


Subdirectory version

Just copy and paste it into your .htaccess above the existing rules and you’ll be all set.

Headless Version: Serve static subfolder to your main domain

One neat way to run WordPress headlessly is by uploading a compiled version of your React.js site to a folder alongside your WordPress install. One of the benefits of this is that you can get around those pesky CORS issues without modifying any rules or fiddling with reverse-proxy shenanigans.

But you still have the problem of WordPress snatching those web requests and trying to serve its own content, or simply 404’ing.

You need to tell browsers where to pull your React.js code from.

Not to worry! Just pop the path to the folder containing your static files for react.js in the generator below (no slashes – just the folder name). The page will reload and your fresh rules will spit out.


Headless version

Just copy and paste it into your .htaccess above the existing rules and you’ll be all set.

Elementor Page Builder

Related Articles

Copyright © 2019 Nodeflame

How to: Load a subdirectory independently of WordPress (avoid WordPress 404s)

by nodeflame time to read: 1 min