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
herrvigg opened this issue Jun 21, 2018 · 11 comments
Closed

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

herrvigg opened this issue Jun 21, 2018 · 11 comments
Labels
legacy issue Legacy issue imported from original repo need info The submitter must provide more info

Comments

@herrvigg
Copy link
Collaborator

herrvigg commented Jun 21, 2018

Issue by brodock
Tuesday Mar 31, 2015 at 18:13 GMT
Originally opened as qTranslate-Team/qtranslate-x#110


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.

@herrvigg herrvigg added enhancement New feature or request legacy issue Legacy issue imported from original repo need info The submitter must provide more info labels Jun 21, 2018
@herrvigg herrvigg changed the title Menu - Cannot change URL's in sub item per language redirect loop on Nginx, MySQL, PHP (LEMP) Stack on Debian 7 Jun 23, 2018
@herrvigg herrvigg removed the enhancement New feature or request label Jun 23, 2018
@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Tuesday Mar 31, 2015 at 19:57 GMT


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.

@herrvigg
Copy link
Collaborator Author

Comment by brodock
Thursday Apr 02, 2015 at 16:46 GMT


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.

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Thursday Apr 02, 2015 at 16:50 GMT


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.

@herrvigg
Copy link
Collaborator Author

Comment by brodock
Thursday Apr 02, 2015 at 17:04 GMT


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

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Thursday Apr 02, 2015 at 17:06 GMT


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

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

@herrvigg
Copy link
Collaborator Author

Comment by brodock
Thursday Apr 02, 2015 at 17:14 GMT


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

@herrvigg
Copy link
Collaborator Author

Comment by brodock
Thursday Apr 02, 2015 at 17:17 GMT


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;
        }

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Thursday Apr 02, 2015 at 17:21 GMT


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 👍

@herrvigg
Copy link
Collaborator Author

Comment by brodock
Thursday Apr 02, 2015 at 17:29 GMT


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

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Thursday Apr 02, 2015 at 17:32 GMT


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.

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Thursday Apr 02, 2015 at 17:48 GMT


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
legacy issue Legacy issue imported from original repo need info The submitter must provide more info
Projects
None yet
Development

No branches or pull requests

1 participant