OMi Shah
OMi Shah

Reputation: 6186

Apache - .htaccess Rewrite Rules, unable to see the existing files content

I am developing an IFSC code finder script.

I have some files already named about.php, privacy-policy.php, contact-us.php, and some other files and folders.

My .htaccess file content is:

RewriteEngine on

RewriteRule ^index.html$ index.php [L]
RewriteRule ^about.html$ about.php [L]
RewriteRule ^privacy-policy.html$ privacy-policy.php [L]
RewriteRule ^contact-us.html$ contact-us.php [L]
RewriteRule ^search.html$ search.php [L]

RewriteRule ^(.*)/(.*)/(.*)/(.*)/?$ index.php?bank=$1&state=$2&district=$3&branch=$4 [QSA]
RewriteRule ^(.*)/(.*)/(.*)/?$ index.php?bank=$1&state=$2&district=$3 [QSA]
RewriteRule ^(.*)/(.*)/?$ index.php?bank=$1&state=$2 [QSA]
RewriteRule ^(.*)/?$ index.php?bank=$1 [QSA]

Now, I want that the files which are already existing like about.html or about.php and so on should be shown instead of passing the query to custom rewrite condition. For example when I try to visit http://example.com/ifsc/about.html then the about.html file should be shown instead of passing it as http://example.com/ifsc/?branch=index.html

Thanks :)

Upvotes: -1

Views: 72

Answers (1)

Matteo Steccolini
Matteo Steccolini

Reputation: 1845

Taking inspiration from this other answer, you should probably check beforehand if the requested file (not folder) exists, then skip all rewriterules if it does.

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+) - [PT,L]

(I'm not a guru in mod_rewrite, please double-check)

Upvotes: 1

Related Questions