Difference between #1 and #9 of
Using search engine and user friendly URLs

Changes

Title unchanged

Using search engine and user friendly URLs

Category unchanged

Tutorials

Yii version unchanged

Tags changed

SEO, URL

Content changed

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 */*
<IfModule mod_rewrite.c>
 
RewriteEngine on

# if a directory or a file exists, use it directly
[...]
# otherwise forward it to index.php
RewriteRule . index.php
</IfModule>
 
~~~

Please consult the user reference if you are using a different Web server.
[...]
With the above approach, we can achieve very flexible URL schemes while keeping our code clean. If some day we want to change the format of the detail page URL (e.g., besides title, we also want to add category information into the URL), we can immediately accomplish this by updating only the `getUrl()` method in the base class. If, a model has a very special format for its detail page URL, we can override the `getUrl()` method in this model class.

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`.

 
19 0
31 followers
Viewed: 101 792 times
Version: 1.1
Category: Tutorials
Tags: SEO, URL
Written by: qiang
Last updated by: Yang He
Created on: Oct 23, 2009
Last updated: 11 years ago
Update Article

Revisions

View all history