Place static HTML files in path below WordPress page

I have a WordPress instance running on my domain’s root.

One WordPress page is located at www.example.com/product/.
I placed some static HTML files in a path below that so that visitors can go to www.example.com/product/documentation/ where an index.html and other HTML files live.

Now I can access the static HTML files just fine, but when going to the WordPress site (i.e. www.example.com/product/), I get a 403 Forbidden error.

How can I make the static HTML files available at that URL while retaining access to the WordPress page?

Here is my .htaccess file (I think it is the unmodified default)

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Sorry if this question has been answered already, but I have only found questions about problems with displaying the static content rather than the WordPress content.

1 Answer
1

By creating a physical directory the same as a (virtual) WordPress URL you have created a conflict. The URL needs to be routed through WP, but the default front-controller (the .htaccess code shown above) specifically excludes physical directories from being rewritten.

The 403 Forbidden error comes about because you don’t have a directory index document (eg. index.html or index.php) in the /product subdirectory. (And neither do you want one, just in case you were wondering.)

Depending on your site, you could simply remove the directory check in the front controller. For example (just commented out):

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

This will mean that requests for any physical directories (just the bare directory) will not be accessible, they will be passed through WP. However, this will likely conflict with your /product/documentation/ URL. In which case, you can add something like the following before the above directives:

RewriteRule ^product/documentation/$ /product/documentation/index.html [L]

(Otherwise, you’ll get a WordPress 404 if any physical directory is requested, where the URL does not exist in WP.)

Alternatively, you can explicitly make an exception for this one subdirectory and manually route it through WP (ie. rewrite it to index.php). For example, before the existing front controller (at the top of the file), add the following:

RewriteRule ^product/?$ /index.php [L]

Leave a Comment