I am trying to configure my .htaccess file to redirect all URI requests, including folders, to index.php. Here is the structure of my root directory:
- app
- admin
- public
- index.php
- .htaccess
My goal is to redirect requests as follows:
www.example.com/anything -> Pass! Successfully redirected to index.php, no HTTP errors. www.example.com/admin -> Not Pass! Displays HTTP error: Forbidden (You don't have permission to access this resource.)
Any other request works fine, only when I try to access a URI that contains a folder with the same name I get http forbidden error
I want to handle all URI requests as normal GET requests to index.php. How can I achieve this?
Here is my current .htaccess configuration:
<IfModule mod_rewrite.c>
Options -MultiViews -Indexes +FollowSymLinks
# Turn rewriting on
RewriteEngine On
RewriteBase /
# Redirect http
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
# Redirect requests to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [NC,L,QSA]
# proc/self/environ? no way!
RewriteCond %{QUERY_STRING} proc/self/environ [OR]
# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
</IfModule>
UPDATE:
Following the reply from @arkascha. I did remove the -Indexes from Options and remove the directory condition. Although I am getting the following error when I tried to access the URI www.example.com/admin:
example.com redirected you too many times. ERR_TOO_MANY_REDIRECTS
.htaccess configuration revised:
Options -MultiViews +FollowSymLinks
# Redirect requests to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [NC,L,QSA]