After some digging it looks like that the reason why my nginx rules don't
work is how the _url() in CakeRequest.php is written.

        if (!empty($_SERVER['PATH_INFO'])) {
            return $_SERVER['PATH_INFO'];
        } elseif (isset($_SERVER['REQUEST_URI'])) {
            $uri = $_SERVER['REQUEST_URI'];
        } elseif (isset($_SERVER['PHP_SELF']) &&
isset($_SERVER['SCRIPT_NAME'])) {
            $uri = str_replace($_SERVER['SCRIPT_NAME'], '',
$_SERVER['PHP_SELF']);
        } elseif (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
            $uri = $_SERVER['HTTP_X_REWRITE_URL'];
        } elseif ($var = env('argv')) {
            $uri = $var[0];
        }
       ...

PATH_INFO is empty on my server,
Next in line is REQUEST_URI and it contains the ORIGINAL URL (without the
parameters ?&) written in the browser and not the rewritten one (that would
be in QUERY_STRING) . So no matter what is in the rewrite rules is in
nginx, I will always end up with what the address that the user typed in
the browser.

I may be wrong but QUERY_STRING should be used in Cake instead than
REQUEST_URI.

Best,
    Chris


On Tue, Apr 24, 2012 at 1:36 PM, Chris Cinelli <
[email protected]> wrote:

> Where is in cakePHP the code that reads the _GET parameters and do the
> routing to the controller?
>
> @Mark:
> I will try the format at *
> http://book.cakephp.org/2.0/en/installation/advanced-installation.html#pretty-urls-on-nginx
> * but the current one wrote in the previews email seems to work fine.
> Should not it?
>
> @lowpass: The idea is to have 2 site-available in nginx. One has
> "server_name www.olddomain.com;" another "server_name 
> www.newdomain.com<http://www.olddomain.com/>;".
> The new one would have a standard nginx configuration for cakephp. The old
> one wanted to "redirect" every controller/action (not really a redirect but
> a rewrite of the url in nginx)  to the controller/action OldSite/home with
> the "real url" the user is trying to access in the newurl param. In this
> way the only code that has to be aware of the old domain is in
> OldSiteController.php and in the olddomain.conf file in nginx.
>
> Best,
>     Chris
>
>
>
> On Tue, Apr 24, 2012 at 1:03 PM, lowpass <[email protected]> wrote:
>
>> I don't see why you'd want to pass the entire URL for the old domain.
>> In any case, leave Cake's 'url' param alone and instead rewrite as
>> (ONLY if the request is for the old domain):
>>
>> /index.php?foo=bar&url=$1
>>
>> Then check to see if the foo param exists. If it does, throw up a
>> flash message with your notice. Of course, 'foo' & 'bar' can be
>> whatever you want. Just some simple flag to let your app know that
>> this request was redirected from the old domain.
>>
>> And be sure to make it a 301 redirect.
>>
>> On Tue, Apr 24, 2012 at 2:19 AM, Chris Cinelli
>> <[email protected]> wrote:
>> > I have a a domain: www.olddomain.com
>> > I am moving to www.newdomain.com
>> >
>> > and I am using currently using nginx with this parameters:
>> >
>> >     server_name www.olddomain.com;
>> >     access_log /var/log/nginx.access.log;
>> >     error_log  /var/log/nginx.error.log debug;
>> >     root /var/www/webroot/;
>> >
>> >     location / {
>> >         index index.php index.html index.htm;
>> >         if (-f $request_filename) {
>> >             break;
>> >         }
>> >         rewrite ^(.+)$ /index.php?url=$1 last;
>> >     }
>> >     location ~ .*\.php[345]?$ {
>> >         fastcgi_pass 127.0.0.1:9000;
>> >         fastcgi_index index.php;
>> >         fastcgi_param SCRIPT_FILENAME
>> /var/www/webroot$fastcgi_script_name;
>> >         include        /etc/nginx/fastcgi_params;
>> >     }
>> >
>> > Now I want to redirect the people that are contacting the old domain
>> the the
>> > exact same place on the new domain BUT I want to communicate the people
>> that
>> > we have a new domain name.
>> >
>> > I thought that the way to do it is to have an address that have a
>> message
>> > that is a little better but not that different than  "We changed name,
>> you
>> > will be redirected in 5 sec" and then redirect them to the new domain
>> (that
>> > nginx should pass as a query parameter called newurl). The redirect
>> splash
>> > page is at /OldSite/home (but using the old rewrite schema - I am using
>> > CakePHP)
>> >
>> > This is my attempt but it does not work:
>> >
>> >     server_name www.olddomain.com;
>> >     access_log /var/log/nginx.access.log;
>> >     error_log  /var/log/nginx.error.log debug;
>> >     root /var/www/html/app/webroot/;
>> >
>> >     location / {
>> >         index index.php index.html index.htm;
>> >         if (-f $request_filename) {
>> >             break;
>> >         }
>> >         rewrite ^(.+)$
>> > /index.php?url=/OldSite/home?urlnew=www.newdomain.com/$request_urilast;
>> >    }
>> >
>> > It looks like the rewrite work but it seems that cakePHP does some
>> magic and
>> > I see the same as I did not change anything: the site completely ignore
>> > "/OldSite/home?urlnew=www.newdomain.com/". I am not sure what CakePHP
>> is
>> > doing at the routing level.
>> >
>> > Anyway, how can I make it work?
>> >
>> > Best,
>> >    Chris
>> >
>> > --Everything should be made as simple as possible, but not simpler
>> (Albert
>> > Einstein)
>> >
>> > --
>> > Our newest site for the community: CakePHP Video Tutorials
>> > http://tv.cakephp.org
>> > Check out the new CakePHP Questions site http://ask.cakephp.org and
>> help
>> > others with their CakePHP related questions.
>> >
>> >
>> > To unsubscribe from this group, send email to
>> > [email protected] For more options, visit this
>> group at
>> > http://groups.google.com/group/cake-php
>>
>> --
>> Our newest site for the community: CakePHP Video Tutorials
>> http://tv.cakephp.org
>> Check out the new CakePHP Questions site http://ask.cakephp.org and help
>> others with their CakePHP related questions.
>>
>>
>> To unsubscribe from this group, send email to
>> [email protected] For more options, visit this group
>> at http://groups.google.com/group/cake-php
>>
>
>
>
> --
> --Everything should be made as simple as possible, but not simpler (Albert
> Einstein)
>



-- 
--Everything should be made as simple as possible, but not simpler (Albert
Einstein)

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to