Sometimes, it is important to allow access to a file or directory but don’t require a sub domain. For example, when you upload a file or folder to your public_html directory, but WordPress shows a 404 error while attempting to access its file path. In such cases, you can create a rewrite condition within your .htaccess file to force your WordPress website to ignore the file path of that file. With this a file – e.g. domain.com/file.html – will get displayed as is instead of embedded as part of the parent WordPress website.
Steps to Edit WordPress to Ignore a File Path
- Login to your account via SSH or cPanel File Editor, navigate to your WordPress directory.
- Open your website with .htaccess file.
- Check below the default WordPress .htaccess file:
# BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress
Add the below code above the RewriteCond lines, replacing file with the file path to your saved files:
RewriteCond $1 !^(/file)
- Then save your changes.