Need Help On Url Rewriting


I have developed an entire website in Yii-Framework. I am using Yii Url Rewrite.


My client asked that he wants url look like

(added slash in the end)

Also he wants that if someone opens he/she should redirected to he/she should redirected to

He also wants to add this tag on every page of site:

<link rel="canonical" href="" />

How to do this?

Please help.

Add this to url manager:

'urlSuffix' => '/',

I’m sure you can work out the canonical part.

A friendly tip…

Personally I hate it when people ask questions and then say it’s urgent. I do this in my free time for no pay and don’t give a damn how urgent somebody else’s project is. I consider it disrespectful imho.

Thanks. It is now generating urls with "/" in end but if someone requests a url without "/" in end then it should redirect to the "/" version. How to do this redirection?

Are you Google-phobic or something? :)

I already checked that page. I don’t understand all the htaccess code perfectly. Therefore when I used the code from that url it also didn’t worked for me.

Here is my .htaccess file

Options +FollowSymLinks

IndexIgnore /

RewriteEngine on

if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

otherwise forward it to index.php

RewriteRule . index.php

Now please tell me what should I modify?

htaccess rules are tricky. So just try.

It’s a valuable skill to acquire.

As Jacmoe says…

Keep up your search on htaccess until you find something appropriate.

It’s not Yii specific and you might find it doesn’t work well on localhost with root in a sub-folder anyway.

It’s kind of a “suck and see” kind of thing specific to your situation.


I ended up with this solution:

I placed this code in global controller class constructor(i.e. the class from which all controller classes extend)

$slash = substr($this->request->url, -1);

$url = $this->request->hostInfo.$this->request->url;

if($slash != "/"){


$url = $this->request->hostInfo.$this->request->url."/";