This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

[SOLVED] Weird redirection on a new server

Discussion relating to version 1.2.x stable

[SOLVED] Weird redirection on a new server

by Gaff » Thu Dec 08, 2011 10:38 am

When submiting a form, I've got this traces in the logs

Code: Select all
    Dec 06 14:43:23 symfony [info] {sfFrontWebController} Redirect to "http://example.com, example.com, example.com/myapp/backend_dev.php/post/1/edit"
    Dec 06 14:43:23 symfony [info] {sfWebResponse} Send status "HTTP/1.1 302 Found"
    Dec 06 14:43:23 symfony [info] {sfWebResponse} Send header "Location: http://example.com, example.com, example.com/myapp/backend_dev.php/post/1/edit"
    Dec 06 14:43:23 symfony [info] {sfWebResponse} Send header "Content-Type: text/html; charset=utf-8"
    Dec 06 14:43:23 symfony [info] {sfWebResponse} Send content (176 o)


The url displayed in the browser's adsress bar is : http://example.com, example.com, example.com/myapp/index.php/post/new

It is very weird since it works on my station (wampserver 2.0 and PHP 5.2.9).

I have no clues at the moment of the origin of this problem (except it never worked in this new environment - apache/ PHP 5.3).

Thank you in advance for any hint,

Lilian.
Gaff
Junior Member
 
Posts: 8
Joined: Wed Mar 03, 2010 3:43 pm

Re: Weird redirection on a new server

by rtome » Fri Dec 09, 2011 4:28 pm

Hi there.

You should check if you've got a .htaccess file with these redirections in. That's the first thing that comes to mind for me with an apache environment.

If there is one, the .htaccess file would probably be wherever your web root directory is.
rtome
Junior Member
 
Posts: 21
Joined: Thu Jan 10, 2008 11:49 am
Location: France

Re: Weird redirection on a new server

by Gaff » Tue Jan 31, 2012 12:13 pm

First,

Thank you very much for your answer.
I really think that the .htaccess is not in cause (it is the same file on both environment) but you can see it below
Code: Select all
Options +FollowSymLinks +ExecCGI

<IfModule mod_rewrite.c>
  RewriteEngine On

  # uncomment the following line, if you are having trouble
  # getting no_script_name to work
  #RewriteBase /

  # we skip all files with .something
  #RewriteCond %{REQUEST_URI} \..+$
  #RewriteCond %{REQUEST_URI} !\.html$
  #RewriteRule .* - [L]

  # we check if the .html version is here (caching)
  RewriteRule ^$ index.html [QSA]
  RewriteRule ^([^.]+)$ $1.html [QSA]
  RewriteCond %{REQUEST_FILENAME} !-f

  # no, so we redirect to our front web controller
  RewriteRule ^(.*)$ /phone/index.php [QSA,L]
</IfModule>


Second,

I've made some progress on the root cause.

On the new environment, the value of the $this->context->getRouting()->options['context']['host'] variable is not good: it is set to my host x3 ($this is my action/controller)
Litterally , I've got:
Code: Select all
mydomain, mydomain, mydomain

The host name is repeated three times each one separated by a coma.

Below is my apps/frontend/config/factories.yml (without lines starting by #):
Code: Select all
prod:
  logger:
    class:     sfFileLogger
    param:
      level:   warning
      loggers: ~
      file:    %SF_LOG_DIR%/../../../../logs/appli/phone_%SF_APP%_%SF_ENVIRONMENT%.log

dev:
  logger:
    class:     sfFileLogger
    param:
      level:   debug
      loggers: ~
      file:    %SF_LOG_DIR%/../../../../logs/appli/phone_%SF_APP%_%SF_ENVIRONMENT%.log

cli:
  controller:
    class: sfConsoleController
  request:
    class: sfConsoleRequest
  response:
    class: sfConsoleResponse

test:
  storage:
    class: sfSessionTestStorage
    param:
      session_path: %SF_TEST_CACHE_DIR%/sessions

  response:
    class: sfWebResponse
    param:
      send_http_headers: false

all:
  routing:
    class: sfPatternRouting
    param:
      generate_shortest_url:            true
      extra_parameters_as_query_string: true
      debug:                            true
      logging:                          true


I can set the value of the host option by adding this to my factories.yml, but I really don't like it since it should work without that.
Example of the very bad fix
Code: Select all
all:
  routing:
    class: sfPatternRouting
    param:
      generate_shortest_url:            true
      extra_parameters_as_query_string: true
      debug:                            true
      logging:                          true
      context:
        host:                           mydomain


EDIT:
The values of the $_SERVER['SERVER_NAME'] and $_SERVER['HTTP_HOST'] are good. Each one is equal to mydomain

Thank you in advance for any hint,

Lilian.
Gaff
Junior Member
 
Posts: 8
Joined: Wed Mar 03, 2010 3:43 pm

Re: [SOLVED] Weird redirection on a new server

by Gaff » Wed Feb 01, 2012 12:03 pm

phpinfo() did the trick!

In the "Apache Environment" section I have
Code: Select all
X-Forwarded-Host    mydomain, mydomain, mydomain


In the "HTTP Headers Information" section I have the same
Code: Select all
X-Forwarded-Host    mydomain, mydomain, mydomain


Finally in the "PHP Variables" section
Code: Select all
_SERVER["HTTP_X_FORWARDED_HOST"]    mydomain, mydomain, mydomain


What's strange is that symfony choose this variable instead of $_SERVER["HTTP_HOST"] to generate absolute URL.

EDIT : look at this bug http://trac.symfony-project.org/ticket/3842
Gaff
Junior Member
 
Posts: 8
Joined: Wed Mar 03, 2010 3:43 pm