Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

307
Visualizações
Yii2 doesn't find /backend/web after .htaccess changes

I'm trying to get an Yii2 advanced template up on a VPS. Everything works fine in terms of algorithms and pathing until I try to enable 'pretty url' through config files and .htaccess. It works perfectly for /frontend, but /backend can no longer be accessed. I'm still a newbie on .htaccess so any help would be appreciated.

Root .htaccess:

<IfModule mod_rewrite.c>
 RewriteEngine on

 RewriteBase /
 RewriteRule backend backend\.php [T=application/x-httpd-php]

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

# Deny accessing below extensions
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>

# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]

common\config\main.php (urlManager)

        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [ 
                '<controller:\w+>/<id:\d+>' => '<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',     
            ],
        ],

frontend/web/.htaccess

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

I've also tried changing the frontend/config/main.php basePath as such:

use yii\web\Request;
$baseUrl = str_replace('/frontend/web', '', (new Request)->getBaseUrl());

But to no avail, since I would only get a 500 error (and nothing else) while trying to access the server.

Note: mode_rewrite has been enabled both through a2enmod and through apache2.conf.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Yii2 advanced .htaccess configuration

.htaccess

Options -Indexes
Options FollowSymlinks
RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.(.*)$
RewriteRule ^(.*)$ http://%1/$1 [L,R=301]

RewriteCond %{REQUEST_URI} ^/admin/$
RewriteRule ^(admin)/$ /$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule ^admin(/.+)?$ /backend/web/$1 [L,PT]

RewriteCond %{REQUEST_URI} ^.*$
RewriteRule ^(.*)$ /frontend/web/$1

.htaccess - backend

# use mode 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

.htaccess - frontend

<IfModule mod_rewrite.c>
        Options +FollowSymlinks

        # Включаем mod_rewrite и перенаправляем со слэша
        RewriteEngine On
        RewriteBase /
        RewriteCond %{HTTP_HOST} (.*)
        RewriteCond %{REQUEST_URI} /$ [NC]
        RewriteRule ^(.*)(/)$ $1 [L,R=301]

        # Если это папка или файл, открываем ее/его
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        # В противном случае перенаправляем на index.php
        RewriteRule . index.php
</IfModule>

Hope it helps

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda