This is my .htaccess
code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ api.php?rquest=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ api.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ api.php [QSA,NC,L]
RewriteCond %{REQUEST_URI} !^/images/
</IfModule>
My directory structure:
My problem is that I can access my api.php by calling /users
or /getData
etc. But if I go for images/someImage.jpg
then it not allowing.
Try this simple rewrite rule
RewriteBase /your web directory
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ api.php?rquest=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ api.php?rquest=$1
the following is the break down of the code
RewriteBase / #enter your directory root here
RewriteEngine On
the following rewrite rule will redirect for example www.example.com/home to example.com/api.php?rquest=$1
RewriteRule ^([a-zA-Z0-9_-]+)$ api.php?rquest=$1
and the following will redirect for example www.example/home/ to example.com/api.php?rquest=$1. notice the / after /home
RewriteRule ^([a-zA-Z0-9_-]+)/$ api.php?rquest=$1
the above lines of code excludes the rule to redirect www.example.com/images/someimages.jpg to www.example.com/
So this will work for now.