To stop access to a directory (and anything in that directory) all you need is a simple RewriteRule.
RewriteEngine on
RewriteBase /
RewriteRule ^exampledirectory/(.*)$ / [R=301,L]
In this example, if this .htaccess file resides in the root directory of the site and you try to access anything within /exampledirectory you will be redirected back to the root folder. To redirect to another folder (like anotherdirectory) on your web server use the following rule.
RewriteEngine on
RewriteBase /
RewriteRule ^exampledirectory/(.*)$ /anotherdirectory [R=301,L]
Comments
I have a question
When a user opens the url www.domain.com/param
I want it redirected to www.domain.com?param while masking the new url (the URL address displayed remains unchanged)
So that instead of accessing param as a folder, it accesses it as a url GET parameter
Is that possible using .htaccess?
Hi Eric, I think what you want is possible, you need to rewrite the url from one form to the other.
If you look at systems like Drupal and WordPress you'll see that all of their traffic gets re-written by this rule.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
The !-f condition will trigger if the file being requested actually exists. The same thing applied for the !-d condition. Then, all traffic will be routed to the main index.php file, without redirecting away from the current path. You might need to make a couple of modifications to get what you want working, but this should cover most of it.