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, 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.
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
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?
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
The browser asks the server for url A.
The server responds with the redirection to url B, saying "Please ask for B instead of A".
The browser asks the server for url B.
The server returns the content of url B, saying “Here it is. It’s B”.
The browser receives the content of url B.
There are 2 round trips here.
URL Rewriting
The browser asks the server for url A.
The server rewrites url A to B.
The server returns the content of url B, saying “Here it is. It’s A”.
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.