Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nandes2062/aab07eb5d61a5f9738fb751da9af3e93 to your computer and use it in GitHub Desktop.
Save nandes2062/aab07eb5d61a5f9738fb751da9af3e93 to your computer and use it in GitHub Desktop.

#URL Amigables en Yii2 - Configurar correctamente

#1. Dirigirse a aplicacion/config/web.php y agregar o descomentar el siguiente codigo para activar las Url amigables.

 'components' => [
       'urlManager' => [
           'enablePrettyUrl' => true,
           'showScriptName' => false,
           'rules' => [
               '' => 'site/index',
               '<action>'=>'site/<action>',
           ],
       ],
 ],

#2. Crear un archivo .htaccess en la aplicacion/web/.htaccess

Options +FollowSymLinks
IndexIgnore */*

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

#3. Configurar el servidor apache2, ingresar a la Terminal unix EJECUTAR LOS SIGUIENTES COMANDOS PARA ACTIVAR LOS PERMISOS DE ESCRITURA

$ cat /etc/apache2/mods-available/rewrite.load
$ sudo a2enmod rewrite
$ ls -al /etc/apache2/mods-enabled/rewrite.load

#4. Ahora sustituye a todos los "AllowOverride None" por "AllowOverride All" en el archivo de configuración apache2:

$ sudo gedit /etc/apache2/apache2.conf

#5.Finalmente reinicie su servidor apache:

$ sudo service apache2 restart

Listo ahora la aplicacion Yii2 esta configurado correctamente con Url amigables :)

@jiuly256
Copy link

jiuly256 commented Dec 7, 2018

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment