Answer the question
In order to leave comments, you need to log in
How to make a redirect without an htaccess redirect in the root so that the controller in the frontend application works?
rule
[
'pattern' => 'image/get/<filepath:.+>',
'route' => 'image/get,
],
Options +FollowSymlinks
# Включаем mod_rewrite
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/upload [NC]
RewriteCond %{REQUEST_URI} \.(jpg|png|gif)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^upload\/?(.+) /image/get/$1 [NC,L]
# Если запрос начинается с /admin, то заменяем на /backend/web/
RewriteCond %{REQUEST_URI} ^/admin [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^admin\/?(.*) /backend/web/$1 [NC,L]
# Добавляем другой запрос /frontend/web/$1
RewriteCond %{REQUEST_URI} !^/(frontend/web|backend/web) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) /frontend/web/$1
# Mod_Autoindex
<IfModule mod_autoindex.c>
# Запрещаем просмотр содержимого папок
Options -Indexes
</IfModule>
# Mod_Rewrite
<IfModule mod_rewrite.c>
Options +FollowSymlinks
# Включаем mod_rewrite
RewriteEngine On
# Если это папка или файл, открываем её/его
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# В противном случае перенаправляем на index.php
RewriteRule . index.php
</IfModule>
Answer the question
In order to leave comments, you need to log in
You are coming from the wrong side. It is necessary that /upload/file.jpg would lead to image/get. There, take the file using php and give it back. Without redirects, why do you need them?
I'll write how it works.
htaccess rewritten like this
RewriteCond %{REQUEST_URI} ^/upload [NC]
RewriteCond %{REQUEST_URI} \.(jpg|png|gif)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+) /frontend/web/$1 [NC,L]
[
'pattern' => 'upload/<filepath:.+>',
'route' => 'image/get',
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question