Url Rewriting - Where Is It Done?

Hi folks,

I am looking into URL rewriting for SEO in a new application I am creating. Primarily, I would like to rewrite the {controller/action} part of the URL so that it is in different language.

So… is this possible in Yii?

And can someone please explain to me where in the URL rewriting takes place? Is it a function in Yii itself or Apache’s interpretation of the URL string?

Thanks in advance,


it’s UrlManager / http://www.yiiframework.com/doc/guide/1.1/en/topics.url

you can manage rules in config by adding it as component

// config/main.php

<?php return 


	'components' => [

		'urlManager' => [

			'urlFormat' => 'path',

			'showScriptName' => false,

			'rules' => [.....]




  1. you need .htaccess (i guess this will be fine, i dont use apache)

  2. you need urlManager

  3. you need rules for urlManager

Thanks, but I was more looking for information about how the URL is rewritten on a technical level rather than CUrlManager and where I might be able to change the controller/action string to something different.

not sure i understand you.

if you need implementation, look at CUrlManager class, if you need something different - extend it.

if you mean how it works on server, server simply redirects all that url staff to index.php and then urlManager parses original request url into pieces according to your rules.

without server configuration it will be something like


As for the 1st part of your question, I think uEhlO4a has answered it well.

You would be better revise this part of your question with some example.

Thanks for your response.

Basic example, I might want to change ‘www.thewebsite.com/jobs/search’ to ‘www.thewebsite.com/trabajos/buscar’ for the site in Spanish i.e. if the person’s language is recognised as Spanish, can I change the route displayed to something different? If so, where is this done?

I see.

I can’t tell you a fast answer, because I don’t have much experience in i18n.

But I hope some of the search results may help you.


i guess you may want to extend urlManager, especially createUrl()

Thanks for the help guys. I’ll check out those links in more depth later on today.

I think what I was more focusing on is how the URL is created in the browser itself. Is it passed back in the HTTP header?

what do you mean? from spider side there’s no difference




either way you use, internal links will be created url rewritten or not if you used app->createUrl() or something like that,based on your will and configuration of urlManager

A web browser never creates or modifies the url that has been written in the HTML sent by the web server. When the browser has sent ‘http://foo.com/bar/something’ as an url, then the browser will use it as it is, because the browser has no mean to guess that the real url is ‘http://foo.com/index.php?r=bar/something’.

And note that url redirection and url rewriting are different things.

URL Redirection

  1. The browser asks the server for url A.

  2. The server responds with the redirection to url B, saying "Please ask for B instead of A".

  3. The browser asks the server for url B.

  4. The server returns the content of url B, saying “Here it is. It’s B”.

  5. The browser receives the content of url B.

There are 2 round trips here.

URL Rewriting

  1. The browser asks the server for url A.

  2. The server rewrites url A to B.

  3. The server returns the content of url B, saying “Here it is. It’s A”.

  4. The browser receives the content of url B as that of url A.

There is only 1 round trip here. And the browser never knows that the content is actually from a different url.