Yii Framework Forum: CHttpRequest - Rewrite rule behaviour change - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CHttpRequest - Rewrite rule behaviour change Rate Topic: -----

#1 User is offline   Maxximus 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 146
  • Joined: 24-November 08
  • Location:Spain

Posted 11 January 2009 - 05:40 PM

It seems the rewrite rule:

RewriteRule ^(es|en|zh)/?(.*)    index.php/$2?lang=$1 [QSA,L]


Is not working anymore. It seems to be a behaviour change since Yii 1.0.1. CHttpRequest uses $_SERVER['REQUEST_URI'] now in favour of $_SERVER['PATH_INFO'].

Unfortunately is REQUEST_URI not modified by the rewrite rule, so now Yii tries to find a non-existent controller (es for example). So far I could not find a solution.

0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,875
  • Joined: 04-October 08
  • Location:DC, USA

Posted 11 January 2009 - 07:24 PM

Yes, that's the change introduced in 1.0.1. The reason is that PATH_INFO is not always reliable. Could you please post your $_SERVER content and the requested URL?
0

#3 User is offline   Maxximus 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 146
  • Joined: 24-November 08
  • Location:Spain

Posted 12 January 2009 - 05:35 AM

True, PATH_INFO is not always available. Unfortunately the REQUEST_URI will not reflect changes made by the Rewrite engine.
I use the rewrite rule to get improved SEO results for multilang sites.

Here $_SERVER after RewriteRule (local machine, so no GEOIP available):

Array
(
    [REDIRECT_GEOIP_COUNTRY_CODE] => --
    [REDIRECT_GEOIP_COUNTRY_NAME] => N/A
    [REDIRECT_STATUS] => 200
    [GEOIP_COUNTRY_CODE] => --
    [GEOIP_COUNTRY_NAME] => N/A
    [HTTP_HOST] => testdrive
    [HTTP_USER_AGENT] => Mozilla/5.0 (X11; U; Linux x86_64; nl; rv:1.9.0.5) Gecko/2008121623 Ubuntu/8.10 (intrepid) Firefox/3.0.5 FirePHP/0.2.1
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    [HTTP_ACCEPT_LANGUAGE] => nl,en-us;q=0.7,en;q=0.3
    [HTTP_ACCEPT_ENCODING] => gzip,deflate
    [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
    [HTTP_KEEP_ALIVE] => 300
    [HTTP_CONNECTION] => keep-alive
    [HTTP_COOKIE] => lang=nl; PHPSESSID=5233836e96cae49bd854d4461e7358xs
    [HTTP_CACHE_CONTROL] => max-age=0
    [PATH] => /usr/local/bin:/usr/bin:/bin
    [SERVER_SIGNATURE] => <address>Apache/2.2.9 (Ubuntu) DAV/2 SVN/1.5.1 PHP/5.2.6-2ubuntu4 with Suhosin-Patch Server at sg Port 80</address>

    [SERVER_SOFTWARE] => Apache/2.2.9 (Ubuntu) DAV/2 SVN/1.5.1 PHP/5.2.6-2ubuntu4 with Suhosin-Patch
    [SERVER_NAME] => testdrive
    [SERVER_ADDR] => 192.168.1.104
    [SERVER_PORT] => 80
    [REMOTE_ADDR] => 192.168.1.104
    [DOCUMENT_ROOT] => /home/web/htdocs/yii/WebRoot/testdrive
    [SERVER_ADMIN] => [no address given]
    [SCRIPT_FILENAME] => /home/web/htdocs/yii/WebRoot/testdrive/index.php
    [REMOTE_PORT] => 60364
    [REDIRECT_QUERY_STRING] => lang=es
    [REDIRECT_URL] => /es
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => GET
    [QUERY_STRING] => lang=es
    [REQUEST_URI] => /es
    [SCRIPT_NAME] => /index.php
    [PATH_INFO] => /
    [PATH_TRANSLATED] => /home/web/htdocs/yii/WebRoot/testdrive/index.php
    [PHP_SELF] => /index.php/
    [REQUEST_TIME] => 1231756314
    [argv] => Array
        (
            [0] => lang=es
        )

    [argc] => 1
)

Even REDIRECT_URL is not reflecting any change. Could it be a solution to prevail PATH_INFO if available? Perhaps with a switch in urlManager?


0

#4 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,875
  • Joined: 04-October 08
  • Location:DC, USA

Posted 12 January 2009 - 07:25 AM

What is the requested URL?
0

#5 User is offline   Maxximus 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 146
  • Joined: 24-November 08
  • Location:Spain

Posted 12 January 2009 - 08:10 AM

request url is: http://testdrive/es/ (in the above case http://testdrive/es but Apache will add the /)

Rewrite rule makes the QUERY_STRING correctly. In PATH_INFO is the rewritten URI, but not in REQUEST_URI.

Response is: The requested controller "es" does not exist.
0

#6 User is offline   Maxximus 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 146
  • Joined: 24-November 08
  • Location:Spain

Posted 12 January 2009 - 08:26 AM

Might be solvable with a rule in urlManager, only thing I have to define my existing rules twice, and customize createUrl.
0

#7 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,875
  • Joined: 04-October 08
  • Location:DC, USA

Posted 12 January 2009 - 09:35 AM

A simple fix is in your index.php, add the following line before running app:
$_SERVER['REQUEST_URI']=$_SERVER['PATH_INFO'];

The current implementation (v1.0.1) is close to what ZF is doing, which I think is better than our earlier implementation (v1.0.0). But still, there may be situations like yours occur.
0

#8 User is offline   Maxximus 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 146
  • Joined: 24-November 08
  • Location:Spain

Posted 12 January 2009 - 10:04 AM

Yes, that works too. Will use that for now.

Current implementation will not allow any rewrite redirection without this workaround unfortunately.
0

#9 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,875
  • Joined: 04-October 08
  • Location:DC, USA

Posted 12 January 2009 - 10:16 AM

Yes, rewriting rules are really tricky because they could easily turn down the default behavior of frameworks. We will see if there's any other reports about this problem and check if we could provide a better solution.
0

#10 User is offline   extesy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 14-January 09

Posted 14 January 2009 - 04:32 PM

I'd like to see the built-in support for redirect rules as I think it's quite common to use them for SEO purposes. In some cases it's better to use paths instead of query parameters - search engines like that.
0

#11 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,875
  • Joined: 04-October 08
  • Location:DC, USA

Posted 14 January 2009 - 04:36 PM

Check this: http://www.yiiframew...uide/topics.url
0

#12 User is offline   extesy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 14-January 09

Posted 14 January 2009 - 10:44 PM

Ok, if you have a rewrite rule like in the first post, then what would you do without using a workaround (assigning path_info to request_uri)? My point is to have embedded framework support so there is no need in any workarounds.
0

#13 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,875
  • Joined: 04-October 08
  • Location:DC, USA

Posted 15 January 2009 - 06:09 PM

Yes, I am thinking to add an option to allow using $_SERVER['PATH_INFO']. This depends on how many requests for this feature we receive, though.
0

#14 User is offline   Kolyunya 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 21-March 14

Posted 04 June 2014 - 06:42 AM

I've ran inro the exactly same problem. And I vote up for adding the support of `$_SERVER['PATH_INFO']` to the framework core.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users