I want to display a 404 (Not found) message, when the user tries to access unauthorized directory. I do not want to use Forbidden pages. I have tried with below code, but it does not work.
RedirectMatch 404 ^/htaccess/.*$
Any idea on what might be going wrong?
htaccess file is located in the root directory of your WordPress site. Depending on your hosting provider, the root directory may be a folder labelled public_html, www, htdocs, or httpdocs. You can locate it by using File Manager in your hosting account's cpanel. Let's walk through the process step-by-step.
try adding the following to your htaccess file
#if the URI starts with htaccess, return a 404
RewriteRule ^htaccess/ - [R=404,L,NC]
Edit
eg system/function,system/class,...
If you have a lot of folders then use a RewriteCond as below as it is easier to read than multiple folders in a single RewriteRule or multiple RewriteRules, which duplicate the 404 piece
RewriteCond %{REQUEST_URI} ^htaccess/ [NC,OR]
RewriteCond %{REQUEST_URI} ^system/function/ [NC,OR]
#just make sure the last rule does NOT have an OR
RewriteCond %{REQUEST_URI} ^system/class/ [NC]
RewriteRule . - [R=404,L,NC]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With