Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

302
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda