Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

303
Views
Yii2 no encuentra /backend/web después de los cambios de .htaccess

Estoy tratando de obtener una plantilla avanzada de Yii2 en un VPS. Todo funciona bien en términos de algoritmos y rutas hasta que trato de habilitar 'url bonita' a través de archivos de configuración y .htaccess. Funciona perfectamente para /frontend, pero ya no se puede acceder a /backend. Todavía soy un novato en .htaccess, por lo que agradecería cualquier ayuda.

Raíz .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]

común\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>', ], ],

interfaz/web/.htaccess

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

También intenté cambiar el frontend/config/main.php basePath como tal:

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

Pero fue en vano, ya que solo obtendría un error 500 (y nada más) al intentar acceder al servidor.

Nota: mode_rewrite se ha habilitado tanto a través de a2enmod como a través de apache2.conf.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Configuración avanzada de .htaccess de Yii2

.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 - servidor

 # 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 - interfaz

 <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>

Espero eso ayude

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!