0

SEO Friendly URLs in Yii2

This tutorial provides some insights into Apache configuration and Yii2 configuration in order to achieve user friendly and search engine friendly URLs for your web app.

There are 3 way to achieve user friendly and search engine friendly URLs for your web application.

  • First hide frontend/web and backend/web
  • Second enable pretty URL
  • Rewrite URL

 

Hide frontend/web and backend/web

Create .htaccess file on the root directory with this content.

After that you need to configure urlManager in your frontend/config/main.php and backend/config/main.php file.

 

Enable Pretty URL

By Default YII Advanced url structures for frontend and backend are:

yii/index.php?r=controller/action

To make user friendly and SEO friendly url we would like to change frontend url to: yii/controller/action And backend url to: Yii/backend/controller/action For this we need to make following changes:

Step 1 : edit common/config/main.php as below(If not working means add in frontend/config/main.php and backend/config/main.php)

Step 2 : Add following .htaccess file into frontend/web folder

Step 3 :Add following .htaccess file into backend/web folder

 

Rewrite URL

URL Rewrite enables Web administrators to create powerful rules to implement URLs that are easier for users to remember and easier for search engines to find.

Sample User Friendly URL:

  1. http://bottle.ch/frontend/web/index.php to be change http://bottle.ch
  2. http://bottle.ch/frontend/web/index.php?r=site/cuisine to be change http://bottle.ch/cuisine
  3. http://bottle.ch/frontend/web/index.php?r=site/cuisine&cuisineid=Schweizerische Küche to be change http://bottle.ch/cuisine/Schweizerische Küche

 

Prakash S

Prakash S

I would like to introduce myself as a Software professional opting for the career in software industry. I'm Prakash S, a MCA graduate and trained as industry level practice for Software technology. Basically I am a PHP Developer but now days exploring more in HTML5, CSS, AngularJS and jQuery libraries.