I have wordpress installed on a root directory. Wordpress was often so slow, I created a node script which will look at all pages on the website, and a create a static directory for each one with an index.html file.
Before making them static, the directory looks like
/wp-content
/wp-includes
/etc etc etc
After
/wp-content
/wp-includes
/etc etc etc
/page-with-same-url-from-wordpress
/index.html
If I then visit mysite.com/page-with-same-url-from-wordpress/, I am served up the static page. Great, and it loads quick.
The issue is that when I go back to edit the page on wordpress, and want to preview any edits, I still see the overriding index.html content instead of the actual wordpress php content. I see why, but as a workaround, when I want to edit a file, I now need to delete the /page-with-same-url-from-wordpress/ dir which will allow me to see the wordpress changes in preview mode, and when I am done, I run the node script and it creates the /page-with-same-url-from-wordpress/ dir again.
Is there any type of rewrite rule I could add to the .htaccess file that would allow the server to always serve the index.html file UNLESS I am viewing the url in preview mode (which looks like mysite.com/page-with-same-url-from-wordpress/?preview_id=2313
I really appreciate any insight. Thank you.
Relevant part from .htaccess
:
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
.htaccess
file./static
) - this does not need to be in the visible URL. But this would mean you could just add an additional rule to the existing.htaccess
file and not have to change the standard WordPress code block (which is against recommendations).