P
P
Padre2018-02-07 12:52:14
Yii
Padre, 2018-02-07 12:52:14

Which htaccess to use for Yii2 advanced?

There is htaccess in advanced application:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

Everything works for frontend. How to forward the request to backend/web if there is domain.com/admin in the path?
Tried this htaccess
spoiler
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
 
# Если запрос начинается с /admin, то заменяем на /backend/web/
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule ^admin\/?(.*) /backend/web/$1
 
# Добавляем другой запрос /frontend/web/$1
RewriteCond %{REQUEST_URI} !^/(frontend/web|backend/web|admin)
RewriteRule (.*) /frontend/web/$1
 
# Если frontend запрос
RewriteCond %{REQUEST_URI} ^/frontend/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /frontend/web/index.php
 
# Если backend запрос
RewriteCond %{REQUEST_URI} ^/backend/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /backend/web/index.php

Writes 500 Internal Server Error, there are no errors in the logs
If the server looks in the project_root/frontend/web directory, then why do we put a redirect on,
RewriteRule . /backend/web/index.php
we need to put it on,
RewriteRule . ../../backend/web/index.php
but then the server instead of 500 gives a 400 error:
Bad Request Your browser sent a request that this server could not understand.
PS Do I need to throw some kind of htaccess in the backend/web?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-02-07
@yii16

Good afternoon.
This .htaccess is at the root of the application.

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(admin)
RewriteRule ^admin(\/?.*)$ backend/web/$1 [L]
 
RewriteCond %{REQUEST_URI} ^/
RewriteRule ^(\/?.*)$ frontend/web/$1 [L]

Leave this in frontend and backend
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question