E
E
EvgMul2019-05-03 10:15:27
Yii
EvgMul, 2019-05-03 10:15:27

Why does a 302 redirect happen?

Hello. Setting up Apache for a Yii2 project. I work locally through OpenServer. If I prescribe root directories in the OpenServer settings, then everything works well.
I remove the settings and try to set up redirects through .htaccess
Yii2 advanced template. First you need to at least configure routing to frontend / web, then to backend / web.
Here are the .htaccess files I got:
Project root:

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
</IfModule>

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_URI} ^/.*
    RewriteRule ^(.*)$ /frontend/web/$1 [L]
</IfModule>

Frontend/web directory:
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# use index.php as index file
DirectoryIndex index.php

As a result, when trying to go to the main page, for example, redirects occur:
5ccbea78c587a780595802.png
Tell me, please, what is my mistake?
Thanks in advance to all who respond.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
EvgMul, 2019-05-03
@EvgMul

The .htaccess settings were correct. The error was in the Yii configuration. Should have been written for the frontend

'request' => [
    'baseUrl' => ''
]

for backend
'request' => [
    'baseUrl' => '/backend'
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question