Pages

How To Generate SEO Friendly URL in Yii Framework

We can configure the URL in Yii php Framework which helps to generate SEO friendly url. We can do it by using urlManager in our yii application. In this tutorial we are going to use Yii2.0. To make seo friendly url configure the file named web.php in config folder:
  • open web.php file in config folder.
  • add the following code under components
       "urlManager"=>[
            "class"=>"yii\web\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>',
                ]
            ],

  • create .htaccess file under the root directory and wite the following copy code:
    <IfModule mod_rewrite.c>
        # Turn on URL rewriting
        RewriteEngine On
        RewriteBase /project-root/web/

        RewriteCond $1 !^(index\.php|resources|robots\.txt)
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    </IfModule>

Unknown

Phasellus facilisis convallis metus, ut imperdiet augue auctor nec. Duis at velit id augue lobortis porta. Sed varius, enim accumsan aliquam tincidunt, tortor urna vulputate quam, eget finibus urna est in augue.

1 comment:

  1. Thanks for your help. Looking forward for your next blog. Just wanted to know about everything in detail.
    Regards:
    http://www.sellingonlinetoday.com

    ReplyDelete