How to remove index.php and web from URL in yii 2 framework

How to remove index.php and web from URL in yii 2 framework
Reading Time: 2 minutes

In this article, we will learn how to remove index.php and web from URL. This will help us to maintain clean URL of web application which will further help in better Google page rankings.

First, we will remove index.php from URL

  1. First, check mod_rewrite module is enabled in PHP. To check or enable mod_rewrite mode. Read this article.
  2. Now after enabling the mod_rewrite module, we will create the .htaccess file in the web folder. If you have already moved your web folder to root folder then create .htaccess file in the root folder and put the below code in .htaccess file.

After pasting the above code to .htaccess, go to the config file, and put the below code under components section.

After completing all steps, index.php will be removed from your URL and it will look like http://yourdomain.com/web/site/index. If you face any issue then please comment below.

 

Steps to remove the web from URL

  1. First, move all the contents of web folder to root folder. Merge the assets folder of web folder with root folder.
  2. After that open index.php from the root folder and change the path of file links. The original code of index.php will be

    Change this code to below code. You can see I have only changed the path of file links.

    Now, you have removed the web from URL. Your URL will look like http://yourdomain.com/site/index. If you face any issue then please comment below.

One Comment on “How to remove index.php and web from URL in yii 2 framework”

Leave a Reply

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