Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirect loop on Nginx, MySQL, PHP (LEMP) Stack on Debian 7 #110

Closed
brodock opened this issue Mar 31, 2015 · 11 comments
Closed

redirect loop on Nginx, MySQL, PHP (LEMP) Stack on Debian 7 #110

brodock opened this issue Mar 31, 2015 · 11 comments
Labels

Comments

@brodock
Copy link

brodock commented Mar 31, 2015

My client have a wordpress install on a machine bootstrapped following this tutorial: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-debian-7

Your plugin works fine redirecting pages from /my-page to /pt/my-page, but if there is a query string (for example google analytics source tracking, or anything else), than it fails to redirect to a valid url:

accessing : http://example.com/pt/my-page/?something
redirects to: http://example.com/pt/my-page/?q=/my-page/?&something
which redirects again to: http://example.com/pt/my-page/?q=/my-page/&q=/my-page/?&something
and so on...

I believe the problem is in this line:
https://github.com/qTranslate-Team/qtranslate-x/blob/master/qtranslate_core.php#L75

REQUEST_URI does include the query_string, which will never make the comparison for the canonical url match, and will trigger redirection infinitely.

@johnclause
Copy link
Member

REQUEST_URI does include query on all tests servers I tried. Are you sure it is not included on your server? Which version of -X do you use? Can you try the latest from the GitHub, which can be downloaded from page https://github.com/qTranslate-Team/qtranslate-x with "Download ZIP" button: https://github.com/qTranslate-Team/qtranslate-x/archive/master.zip?

Please, paste here $_SERVER vars at trouble from your server, if it indeed has REQUEST_URI without query string. That line will make it redirect on such a server, but that would not be the only problem then. We will need to put special 'if' in a few places then. Let us first understand what is going on.

@brodock
Copy link
Author

brodock commented Apr 2, 2015

Hi @johnclause, I believe you miss understood me.

let's assume I'm accessing http://example.com/my-page/?something and my default language is portuguese (/pt):

The following line will result in $url_orig = http://example.com/my-page/?something

$url_orig = $url_info['scheme'].'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

after that there is this line:

$url_lang = qtranxf_convertURL('',$lang)

which I believe is not outputing http://example.com/my-page/?something but either: http://example.com/pt/?q=my-page/?something and on the second hop, as it will not match, it will append another "q=" and so on...

one of the reasons is because of the whole QTX_URL_QUERY thing, that maybe is incompatible with nginx way of getting permalink to work.

@johnclause
Copy link
Member

Hi, you explained the same thing over, but no new information. I need to see $_SERVER variables as they defined on your server. I also have no idea where 'q=' comes from.

@brodock
Copy link
Author

brodock commented Apr 2, 2015

this is from "info.php"
do you need one generated from a page that goes by wordpress or is it enough?

_SERVER["USER"] www-data
_SERVER["HOME"] /var/www
_SERVER["FCGI_ROLE"]    RESPONDER
_SERVER["QUERY_STRING"] no value
_SERVER["REQUEST_METHOD"]   GET
_SERVER["CONTENT_TYPE"] no value
_SERVER["CONTENT_LENGTH"]   no value
_SERVER["SCRIPT_FILENAME"]  /usr/share/nginx/www/info.php
_SERVER["SCRIPT_NAME"]  /info.php
_SERVER["REQUEST_URI"]  /info.php
_SERVER["DOCUMENT_URI"] /info.php
_SERVER["DOCUMENT_ROOT"]    /usr/share/nginx/www
_SERVER["SERVER_PROTOCOL"]  HTTP/1.1
_SERVER["GATEWAY_INTERFACE"]    CGI/1.1
_SERVER["SERVER_SOFTWARE"]  nginx/1.2.1
_SERVER["REMOTE_ADDR"]  187.94.99.90
_SERVER["REMOTE_PORT"]  50111
_SERVER["SERVER_ADDR"]  192.241.217.197
_SERVER["SERVER_PORT"]  80
_SERVER["SERVER_NAME"]  192.241.217.197
_SERVER["HTTPS"]    no value
_SERVER["REDIRECT_STATUS"]  200
_SERVER["HTTP_HOST"]    192.241.217.197
_SERVER["HTTP_USER_AGENT"]  Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0
_SERVER["HTTP_ACCEPT"]  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
_SERVER["HTTP_ACCEPT_LANGUAGE"] pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3
_SERVER["HTTP_ACCEPT_ENCODING"] gzip, deflate
_SERVER["HTTP_DNT"] 1
_SERVER["HTTP_CONNECTION"]  keep-alive
_SERVER["PHP_SELF"] /info.php
_SERVER["REQUEST_TIME_FLOAT"]   1427994207.662
_SERVER["REQUEST_TIME"] 1427994207

@johnclause
Copy link
Member

There is no query string on this one?
From first reply:

Please, paste here $_SERVER vars at trouble from your server

@brodock
Copy link
Author

brodock commented Apr 2, 2015

I'm sorry, here is a new one:

_SERVER["USER"] www-data
_SERVER["HOME"] /var/www
_SERVER["FCGI_ROLE"]    RESPONDER
_SERVER["QUERY_STRING"] querystring&another=true
_SERVER["REQUEST_METHOD"]   GET
_SERVER["CONTENT_TYPE"] no value
_SERVER["CONTENT_LENGTH"]   no value
_SERVER["SCRIPT_FILENAME"]  /usr/share/nginx/www/info.php
_SERVER["SCRIPT_NAME"]  /info.php
_SERVER["REQUEST_URI"]  /info.php?querystring&another=true
_SERVER["DOCUMENT_URI"] /info.php
_SERVER["DOCUMENT_ROOT"]    /usr/share/nginx/www
_SERVER["SERVER_PROTOCOL"]  HTTP/1.1
_SERVER["GATEWAY_INTERFACE"]    CGI/1.1
_SERVER["SERVER_SOFTWARE"]  nginx/1.2.1
_SERVER["REMOTE_ADDR"]  187.94.99.90
_SERVER["REMOTE_PORT"]  48627
_SERVER["SERVER_ADDR"]  192.241.217.197
_SERVER["SERVER_PORT"]  80
_SERVER["SERVER_NAME"]  192.241.217.197
_SERVER["HTTPS"]    no value
_SERVER["REDIRECT_STATUS"]  200
_SERVER["HTTP_HOST"]    192.241.217.197
_SERVER["HTTP_USER_AGENT"]  Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0
_SERVER["HTTP_ACCEPT"]  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
_SERVER["HTTP_ACCEPT_LANGUAGE"] pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3
_SERVER["HTTP_ACCEPT_ENCODING"] gzip, deflate
_SERVER["HTTP_DNT"] 1
_SERVER["HTTP_CONNECTION"]  keep-alive
_SERVER["PHP_SELF"] /info.php
_SERVER["REQUEST_TIME_FLOAT"]   1427994870.8975
_SERVER["REQUEST_TIME"] 1427994870

@brodock
Copy link
Author

brodock commented Apr 2, 2015

I'm not sure if this applies, but nginx vhost have the following configured:

        location / {
                try_files $uri $uri/ /index.php?q=$uri$is_args&$args;
        }

@johnclause
Copy link
Member

That shows no surprises on REQUEST_URI:

_SERVER["REQUEST_URI"] /info.php?querystring&another=true

which invalidates your previous explanation.

I'm not sure if this applies, but nginx vhost have the following configured:

Aha, this is where 'q=' come from, then fix it 👍

@brodock
Copy link
Author

brodock commented Apr 2, 2015

I was unsure if that line was really needed. I got solved by changing it to:

        location / {
                try_files $uri $uri/ /index.php?$args;
        }

the culprit was that missleading tutorial from digitalocean that my client followed: https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-nginx-on-ubuntu-12-04

I'm filling the missing parts here to help anyone having the same issue.

Thank you very much for your time,

Cheers

@johnclause
Copy link
Member

I am glad, Gabriel, that it was that simple. Can you change the title of this thread, so that people can see that they can get help with this kind of installation? Best regards.

@johnclause johnclause changed the title [3.2.9] redirect loop when query string is present redirect loop on Nginx, MySQL, PHP (LEMP) Stack on Debian 7 Apr 2, 2015
@brodock brodock changed the title redirect loop on Nginx, MySQL, PHP (LEMP) Stack on Debian 7 [3.2.9] redirect loop when query string is present - nginx vhost Apr 2, 2015
@brodock brodock changed the title [3.2.9] redirect loop when query string is present - nginx vhost redirect loop on Nginx, MySQL, PHP (LEMP) Stack on Debian 7 Apr 2, 2015
@johnclause
Copy link
Member

I thought that you may not have the ability to change title, and decided to change it myself. Now I know you can. Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants