Answer the question
In order to leave comments, you need to log in
How to redirect request when file exists?
Good afternoon!
There was a need to redirect the request only if the file exists to index.php using htaccess
Please tell me how to do this
And I’m also interested in how safe it is to include the existing file with such a redirect from index.php
Just in case, I’ll clarify that the directory contains only executable php files, which are twitched through ajax, or to which forms are sent.
Thanks in advance for your help!
Answer the question
In order to leave comments, you need to log in
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ index.php [L,QSA]
I see bad architecture in your approach in advance.
The application should have only one entry point - index.php for everything, ajaxes, forms, etc. etc. Then there will be no need for your question. See how it is implemented in popular frameworks, and you can do the same, or use ready-made components, for example, Symfony has an independent routing component, you can use it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question