In my project I want to restrict access to subdirectories on the server and want to give access to only the root location.
So lets say user hits http://localhost/ he will be shown the index page but if he types http://localhost/somdir he should not be taken to this directory/location and instead redirected to http://localhost loading the index page.
Environment is as follows:
OS: Linux
Server: Apache
Backend is developed in PHP.
To achieve this I am using the .htaccess file with following rules
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^localhost/
RewriteRule ^(.*)$ http://localhost/ [L,R=301]
Here the redirection happens properly but the rewrite condition (RewriteCond) which is put to avoid looping to http://localhost doesn’t seem to be working. The browser is throwing error.
I want to avoid doing this using httpd.conf file of Apache as the application will be distributed and making changes to httpd.conf will not the advisable/feasible.
Any help in this context or suggestions for alternatives will be highly appreciated.
Thanks in advance.