To hide the subfolder in the URL for WordPress-related requests, you can modify your setup slightly. You can keep the root .htaccess file as it is, but make some changes to the .htaccess file in the WordPress subfolder. Here's how you can do it:
- Modify the .htaccess file in the WordPress subfolder (
e.g.,
/wordpress/) as follows:
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
Add this line to prevent exposing the subfolder in the URL
RewriteCond %{REQUEST_URI} !^/wordpress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
By adding the RewriteCond %{REQUEST_URI} !^/wordpress/ condition, you're ensuring that requests to the /wp-admin/ folder won't be affected by this rewrite rule, so the subfolder won't be exposed in the URL for WordPress-related requests.
In your root .htaccess file, you can simplify the rules for rewriting to index.html
:
RewriteEngine On
Exclude requests to the /wordpress/ subfolder from this rule
RewriteCond %{REQUEST_URI} !^/wordpress/
Rewrite rule for frontend
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
With these modifications, WordPress-related requests will still be handled by the WordPress subfolder, and the subfolder won't be exposed in the URL when accessing /wp-admin/. Other requests will be rewritten to index.html in the root folder as before.