Using search engine and user friendly URLs

Comparing #3 with #9

Tags

SEO, URL

Content

The [Definitive Guide](/doc/guide/topics.url) introduces the fundamentals of managing URLs in a Yii application. In this tutorial, we introduce a practical technique that can quickly turn your application into using search-engine-friendly URLs. Asssume we have an application that mainly consists of CRUD operations for several object types. For example, in the blog demo, we need CRUD operations for `Post`, `Comment` and `User`. Using `Post` as an example, our goal is to implement its CRUD operations with the following URLs:

* reading a post: `http://example.com/post/99/this+is+a+sample+post`
[...]
Options +FollowSymLinks
IndexIgnore */*
&lt;<IfModule mod_rewrite.c&gt;>
RewriteEngine on
[...]
# otherwise forward it to index.php
RewriteRule . index.php
&lt;</IfModule&gt;>
~~~
[...]
Finally, it may also be a good idea to implement in the model classes the methods that return other type of URLs. For example, we can implement the `getListUrl()` method in the base class similar to what we do for `getUrl()`. Then we can readily obtain the list page URL for `Post` model using the expression `Post::model()->listUrl`.

 
### Links
 
[Chinese version](http://dreamneverfall.cn/node/97)