V
V
Valera Karmanov2022-03-29 18:08:14
PHP
Valera Karmanov, 2022-03-29 18:08:14

How to redirect request to index.php when there is no file in the directory?

There is such a link https://site.ru/tmp/images/products/kamaz.360x270.jpeg
Naturally, such a file does not exist, but when following this link, if the file does not exist, I need to redirect the request to the index.php file and there already process the link with a router and create the desired file.

The problem is that the design


RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]


Although I'm not sure that it should work, but it seems to me that this is a more or less correct option, which for some reason does not work!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nokimaro, 2022-03-29
@motokraft

Valera Karmanov , that is, you use .htaccess for the Apache web server and are you not embarrassed that the nginx web server gives a 404 error?
With a probability of 100%, you have nginx, followed by apache, which already runs php.
That is, the user's request first comes to nginx, and then it is already sent to apache or not sent.
And nginx is configured so that if this is a request for a static file, in your case .jpg, then it is not passed to apache, but 404 is issued and therefore .htaccess does not work.
The solution is to configure nginx properly.

V
Valera Karmanov, 2022-03-29
@motokraft

The option of creating a separate index.php file in the tmp folder is not suitable!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question