Jumat, 12 Juni 2015

how to create url seo friendly in yii2 basic for linux

0 komentar
how to create url seo friendly in yii2 basic

the first create file in folder root (localhost/basic/web) with name .htaccess
and copy sourcecode :

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


number two open file in config/web.php end copy code:

        'urlManager' => [
            'enablePrettyUrl' => true, //output localhost/basic/web/index.php?r=site/index
            'showScriptName' => false, //output localhost/basic/web/site/index
           
            'rules' => [
                'logout' => 'site/logout',
                'login' => 'site/login',
                '' => 'site/index',
            ],
           
        ], 

for linux edit etc/apache2/site-enabled
set:
<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        DocumentRoot /home/samsul/public_html

        ServerName testproject

          <Directory /home/samsul/public_html>
  Options Indexes FollowSymLinks
  AllowOverride All
  Require all granted
</Directory>
</VirtualHost>

samsul@samsul-Inspiron-N4050:~$ sudo a2enmod rewrite && sudo /etc/init.d/apache2 restart
Enabling module rewrite.
To activate the new configuration, you need to run:
  service apache2 restart
 * Restarting web server apache2                                         [ OK ]
samsul@samsul-Inspiron-N4050:~$





for windows edit httpd.conf remove "#" 

Leave a Reply