My Yii powered website has been live for about a month now (http://tasta.be) and it’s going pretty good. Right now, I’m heavily invested in SEO. I’ve managed to make my URLs a little bit more URL friendly: http://tasta.be/videos/20 for example, but then I got stuck.
I got the documentation and read all of it, but I think I’m currently not making the click to wrap my head around it. There are two things I want to accomplish, but I fail trying to do so:
It sounds like what you are trying to do should be fairly simple
a rule like ‘videos/<id:\d+>’ => ‘videos/view’ should get you what you have now.
To change to your new format you would want to add a new rule before it like (the .+ can be replaced by a more specific regex if appropriate like [A-Za-z0-9_-]+).
‘videos/<id:\d+>-<urlfield:.+>’ => ‘videos/view’
As for the redirects, here is the way I did that. Each relevant action calls this function near it’s start to redirect if necessary. The $url parameter can be created with Yii::app()->createUrl() as you would creating links to it anywhere else.
* Redirect to the specified URL if we are not already there.
* This is necessary for SEO optimization (search engines penalize for duplicate content at different URLs).
* Duplicate URLs will happen because of stuff like picture/story titles changing, category hierarchy changes,
* and simply all the old URLs that are redirected to the new ones.
* @param String $url The correct URL for this page
if(Yii::app()->request->requestUri != $url)
//header("HTTP/1.1 301 Moved Permanently");
header("Location: $url", true, 301);
Softark’s method would also work and is more powerful, but is probably less efficient if the simple url rules do what you need.