How to enable pretty urls in yii 2 framework

How to enable pretty urls in yii 2 framework
Reading Time: < 1 minute

Today we are going to learn how to enable pretty URLs in Yii 2 framework. Pretty URLs is a need of every website to improve google ranking. To enable pretty URLs in Yii 2, you have to first enable the mod_rewrite module in apache.

Steps to enable pretty URLs in Yii 2

  1. First, check mod_rewrite module is enabled in PHP. To check or enable mod_rewrite mode. Read this article.
  2. After that create .htaccess file in web folder or if you have moved web folder to root folder then create .htaccess file there and put the below code in .htaccess file.
  3. The last step is to add below code in config under components section.

    After completing all these steps your URL will look like http://yourdomain.com/web/site/index. If you have removed the web from URL then it will look like this. http://yourdomain.com/site/index. You can make proper clean URLs by removing index.php and web folder from URL. To do this click here to read an article.

Leave a Reply

Your email address will not be published. Required fields are marked *