L
L
lightalex2017-03-15 18:16:40
PHP
lightalex, 2017-03-15 18:16:40

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

2 answer(s)
A
Andrey Burov, 2017-03-15
@lightalex

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ index.php [L,QSA]

this does not affect the work of PHP and include

E
Evgeny Svirsky, 2017-03-15
@e_svirsky

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 question

Ask a Question

731 491 924 answers to any question