Nginx doesn't redirect www no m in Safari, iPhone, iPad

The problem is, the site is entered with www in url in a mobile device
with
parameters in the url, it is redirected from www.domain.com to
m.domain.com
but the parameters entered with www.domain.com/parameters when
redirected to
m.domain.com doesn’t receive the parameters from thr url origin in www.

In conclusion www.domain.com/parameters should redirect to
m.domain.com/parameters but is redirected to m.domain.com, the
parameters
are clean. Is there a way no to clean it ?

The www config is the following :

server {
listen 80;
server_name www.domain.com;

  #to detect if the device with www entered in domain is mobile
  if ($http_user_agent ~*

‘(iPhone|iPod|iPad|Android|BlackBerry|webOS|Windows Phone)’) {
rewrite ^ http://m.domain.com$uri;
}

}

The mobile configuration is
server {
listen 80;
server_name m.domain.com;

    ...

}

Posted at Nginx Forum:

On Fri, Jul 03, 2015 at 07:04:20AM -0400, ramsoft75 wrote:

Hi there,

In conclusion www.domain.com/parameters should redirect to
m.domain.com/parameters but is redirected to m.domain.com, the parameters
are clean. Is there a way no to clean it ?

It works for me as-is. I add your “if” at server{} level, and I see:

curl -A iPad -i http://localhost/parameters?key=value

HTTP/1.1 302 Moved Temporarily

Location: http://m.domain.com/parameters?key=value

What response do you get for a similar curl command?

f

Francis D. [email protected]

Hi there thanks for the help

i run the following :

curl -A iPad -i Website Domain Names, Online Stores & Hosting - Domain.com

and the result was :

-bash: !/pt/–item/pt/32516/Farinha : event not found

But this page exist’s and is running in desktop in a pc

Posted at Nginx Forum:

Hi there thanks for the help there was an erro

not “-bash: !/pt/–item/pt/32516/Farinha : event not found”

but

"
-bash: "#!/pt/–item/pt/32516/Farinha : event not found

Posted at Nginx Forum:

On Sat, Jul 04, 2015 at 02:03:47PM -0400, ramsoft75 wrote:

Hi there,

i run the following :

curl -A iPad -i Website Domain Names, Online Stores & Hosting - Domain.com

and the result was :

-bash: !/pt/–item/pt/32516/Farinha : event not found

A few things here:

“!” is special to bash, so you have to shell-escape it for “curl” to see
it.

“#” is special in a url; it is not part of the normalised variable $uri.

Possibly using $request_uri instead of $uri in your configuration will
be appropriate? They are different variables with different values,
so there are probably some cases where using one will break things.

Since you are using it in a redirect, probably $request_uri is the
correct one to use regardless.

f

Francis D. [email protected]

Hi there

I changed to

#to detect if the device with www entered in domain is mobile
if ($http_user_agent ~*
‘(iPhone|iPod|iPad|Android|BlackBerry|webOS|Windows
Phone)’) {
rewrite ^ http://m.domain.com$request_uri;
}

I executed the command :

$ curl -A iPad -i

And the result was :

-bash: !/pt/–item-view/pt/32081/Mix-J: event not found

This only append’s with Safari, there’s no problem with Chrome (Desktop,
Mobile) or Internet Explorer in Pc, could this be a browser problem and
not
an Nginx configuration problem ?

Thanks

Posted at Nginx Forum:

On Sun, Jul 05, 2015 at 03:31:22PM -0400, ramsoft75 wrote:

Hi there

This only append’s with Safari, there’s no problem with Chrome (Desktop,
Mobile) or Internet Explorer in Pc, could this be a browser problem and not
an Nginx configuration problem ?

For one request that gets the response you expect, what does access.log
say that the request and user-agent are?

For one request that does not get the response you expect, what does
access.log say that the request and user-agent are?

Perhaps that will hint at where the problem is.

f

Francis D. [email protected]

Good day

There was a problem in testing in the terminal with the character “!”,
it
should be with "" after, like this :

$ curl -A iPad -i

And the result was :

HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Mon, 06 Jul 2015 08:50:10 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: http://m.alpha.centroproduto.com/

301 Moved Permanently

301 Moved Permanently


nginx

And in this case i changed the nginx configuration to :

if ($http_user_agent ~*
‘(iPhone|iPod|iPad|Android|BlackBerry|webOS|Windows
Phone)’) {
rewrite ^/$ http://m.domain.com/$1 permanent;
}

Posted at Nginx Forum:

Hi

I tested in a iPad and Safari the request and the nginx log reported a
401
error :

xxx.xxx.xxx.xxx - - [06/Jul/2015:13:42:24 +0000] “GET
/pt/api_cp/user_counts/ HTTP/1.1” 401 27 “http://m.domain.com/
“Mozilla/5.0
(iPad; CPU OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko)
Version/8.0 Mobile/12F69 Safari/600.1.4”

But this i think is not an error associated with faulty url

Posted at Nginx Forum:

I 'am running Nginx with logging in debug mode and the report for “^/$”
is
:

2015/07/06 15:32:21 [debug] 6500#0: *9 accept: 193.137.170.139 fd:20
2015/07/06 15:32:21 [debug] 6500#0: *9 event timer add: 20:
60000:1436196801837
2015/07/06 15:32:21 [debug] 6500#0: *9 reusable connection: 1
2015/07/06 15:32:21 [debug] 6500#0: *9 epoll add event: fd:20 op:1
ev:80000001
2015/07/06 15:32:21 [debug] 6500#0: accept() not ready (11: Resource
temporarily unavailable)
2015/07/06 15:32:21 [debug] 6500#0: *9 post event 0000000000AC5440
2015/07/06 15:32:21 [debug] 6500#0: *9 delete posted event
0000000000AC5440
2015/07/06 15:32:21 [debug] 6500#0: *9 http wait request handler
2015/07/06 15:32:21 [debug] 6500#0: *9 posix_memalign:
0000000000922D70:256
@16
2015/07/06 15:32:21 [debug] 6500#0: *9 malloc: 0000000000A450C0:1024
2015/07/06 15:32:21 [debug] 6500#0: *9 recv: fd:20 427 of 1024
2015/07/06 15:32:21 [debug] 6500#0: *9 reusable connection: 0
2015/07/06 15:32:21 [debug] 6500#0: *9 posix_memalign:
0000000000A46810:4096
@16
2015/07/06 15:32:21 [debug] 6500#0: *9 http process request line
2015/07/06 15:32:21 [debug] 6500#0: *9 http request line: “GET /
HTTP/1.1”
2015/07/06 15:32:21 [debug] 6500#0: *9 http uri: “/”
2015/07/06 15:32:21 [debug] 6500#0: *9 http args: “”
2015/07/06 15:32:21 [debug] 6500#0: *9 http exten: “”
2015/07/06 15:32:21 [debug] 6500#0: *9 posix_memalign:
0000000000A47E10:4096
@16
2015/07/06 15:32:21 [debug] 6500#0: *9 http process request header line
2015/07/06 15:32:21 [debug] 6500#0: *9 http header: “Host:
www.domain.com
2015/07/06 15:32:21 [debug] 6500#0: 9 http header: “Accept-Encoding:
gzip,
deflate”
2015/07/06 15:32:21 [debug] 6500#0: 9 http header: "Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,
/
;q=0.8"
2015/07/06 15:32:21 [debug] 6500#0: *9 http header: “Accept-Language:
pt-pt”
2015/07/06 15:32:21 [debug] 6500#0: *9 http header: “Cookie:
cookie=true;
lang=pt; _ga=GA1.2.894621310.1424776292”
2015/07/06 15:32:21 [debug] 6500#0: *9 http header: “Connection:
keep-alive”
2015/07/06 15:32:21 [debug] 6500#0: *9 http header: “DNT: 1”
2015/07/06 15:32:21 [debug] 6500#0: *9 http header: “User-Agent:
Mozilla/5.0
(iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML,
like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53”
2015/07/06 15:32:21 [debug] 6500#0: *9 http header done
2015/07/06 15:32:21 [debug] 6500#0: *9 event timer del: 20:
1436196801837
2015/07/06 15:32:21 [debug] 6500#0: *9 generic phase: 0
2015/07/06 15:32:21 [debug] 6500#0: *9 rewrite phase: 1
2015/07/06 15:32:21 [debug] 6500#0: *9 http script var
2015/07/06 15:32:21 [debug] 6500#0: *9 http script var: “Mozilla/5.0
(iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML,
like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53”
2015/07/06 15:32:21 [debug] 6500#0: *9 http script regex:
“(iPhone|iPod|iPad|Android|BlackBerry|webOS|Windows Phone)”
2015/07/06 15:32:21 [notice] 6500#0: *9
“(iPhone|iPod|iPad|Android|BlackBerry|webOS|Windows Phone)” matches
“Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X)
AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257
Safari/9537.53”, client: 193.137.170.139, server: www.domain.com,
request:
“GET / HTTP/1.1”, host: “www.domain.com
2015/07/06 15:32:21 [debug] 6500#0: *9 http script if
2015/07/06 15:32:21 [debug] 6500#0: *9 http script regex: “^/$”
2015/07/06 15:32:21 [notice] 6500#0: *9 “^/$” matches “/”, client:
193.137.170.139, server: www.domain.com, request: “GET / HTTP/1.1”,
host:
www.domain.com
2015/07/06 15:32:21 [debug] 6500#0: *9 http script copy:
http://m.domain.com/
2015/07/06 15:32:21 [debug] 6500#0: *9 http script capture: “”
2015/07/06 15:32:21 [debug] 6500#0: *9 http script regex end
2015/07/06 15:32:21 [notice] 6500#0: *9 rewritten redirect:
http://m.domain.com/”, client: 193.137.170.139, server: www.domain.com,
request: “GET / HTTP/1.1”, host: “www.domain.com
2015/07/06 15:32:21 [debug] 6500#0: *9 http finalize request: 301, “/?”
a:1,
c:1
2015/07/06 15:32:21 [debug] 6500#0: *9 http special response: 301, “/?”
2015/07/06 15:32:21 [debug] 6500#0: *9 http set discard body
2015/07/06 15:32:21 [debug] 6500#0: *9 xslt filter header
2015/07/06 15:32:21 [debug] 6500#0: *9 HTTP/1.1 301 Moved Permanently

Posted at Nginx Forum:

I entered in a url an url similar to the tested before :

And the Nginx didn’t recorded the access in the nginx access.log file

Posted at Nginx Forum:

The “^/$” came from :

#to detect if the device with www entered in domain is mobile
if ($http_user_agent ~*
‘(iPhone|iPod|iPad|Android|BlackBerry|webOS|Windows
Phone)’) {
rewrite ^/$ http://m.domain.com$request_uri;
}

Posted at Nginx Forum:

Hi

I think the part where de parameters are clean is :

2015/07/06 15:32:21 [debug] 6500#0: *9 http script copy:
http://m.domain.com/
2015/07/06 15:32:21 [debug] 6500#0: *9 http script capture: “”
2015/07/06 15:32:21 [debug] 6500#0: *9 http script regex end
2015/07/06 15:32:21 [notice] 6500#0: *9 rewritten redirect:
http://m.domain.com/”, client: xxx.xxx.xxx.xxx, server: www.domain.com,
request: “GET / HTTP/1.1”, host: “www.domain.com
2015/07/06 15:32:21 [debug] 6500#0: *9 http finalize request: 301, “/?”
a:1,
c:1
2015/07/06 15:32:21 [debug] 6500#0: *9 http special response: 301, “/?”
2015/07/06 15:32:21 [debug] 6500#0: *9 http set discard body
2015/07/06 15:32:21 [debug] 6500#0: *9 xslt filter header
2015/07/06 15:32:21 [debug] 6500#0: *9 HTTP/1.1 301 Moved Permanently

I can’t understand the last lines, what does it means

Posted at Nginx Forum:

On Mon, Jul 06, 2015 at 12:40:37PM -0400, ramsoft75 wrote:

Hi there,

Things seem to be getting a lot more complicated than they need to.

The “^/$” came from :

#to detect if the device with www entered in domain is mobile
if ($http_user_agent ~* ‘(iPhone|iPod|iPad|Android|BlackBerry|webOS|Windows
Phone)’) {
rewrite ^/$ http://m.domain.com$request_uri;
}

That’s not the configuration you started with.

You indicated that with your starting configuration, some requests did
get the response that you wanted, and some did not.

I have been unable to reproduce the “did not” case; probably because I
do not fully understand what your expectations are.

Can you go back to your starting configuration, and do whatever it takes
to get the “ok” request/response, and then show the access_log entry
for that request?

(Or just find the old log file.)

The log line should show a GET going to the “www” server, with a
response
code of 302. Ideally, it will also show the user-agent involved.

Then can you show the log line corresponding to a “not ok”
request/response? It should also show a GET going to the “www” server,
with a response code of 302, if I have understood correctly what you
have reported.

Comparing the two log lines, particularly the request and the
user-agent,
may show why the “not ok” one responded as it did.

f

Francis D. [email protected]

Why don’t you try with requests to real pages, not to a fragment?
“#” and everything after this character isn’t sent to the web server,
it’s
only used by the web client.
You really should read at least:

Some browsers will keep the fragment after the redirect, some others
will
drop it.

Posted at Nginx Forum:

You should protect the URL with single quotes, to avoid the
interpretation
of character ! by the shell:

curl -A iPad -i
Website Domain Names, Online Stores & Hosting - Domain.com

But if you put the URL
Website Domain Names, Online Stores & Hosting - Domain.com in a browser (at
least in Firefox), the browser sends to the web server only the first
part
of that URL:

https://www.domain.com/

because the character # is a special one.

Surprisingly, curl sends the full URL to the webserver.

Greetings,

Oscar

Hello,

Francis D. asked you several times to check the access.log file (you
should not find the fragment part in there).
oscaretu and I told you browsers don’t send the fragment part of an URL.

The problem isn’t from nginx nor the browser: it’s a normal behavior.

Best Regards

Posted at Nginx Forum:

Hi there all and thank’s for the help

Dear oscaretu, the curl was tested with " doesn’t help, because ! is a
special character it needs a escaope after "", so the correct curl
command
for the terminal is :

$ curl -A iPad -i Website Domain Names, Online Stores & Hosting - Domain.com

Dear Francis D.

For the initial configuration :

if ($http_user_agent ~*
‘(iPhone|iPod|iPad|Android|BlackBerry|webOS|Windows
Phone)’) {
rewrite ^ http://m.domain.com/$request_uri;
}

For the example above the output in terminal is :

HTTP/1.1 302 Moved Temporarily
Server: nginx
Date: Tue, 07 Jul 2015 09:19:47 GMT
Content-Type: text/html
Content-Length: 154
Connection: keep-alive
Location: http://m.domain.com//

302 Found

302 Found


nginx

It’s the same if i changed to :

if ($http_user_agent ~*

‘(iPhone|iPod|iPad|Android|BlackBerry|webOS|Windows Phone)’) {
rewrite ^/$ http://m.domain.com/$request_uri;
}

The problem is not from Nginx but from Safari witch doesn’t send the url
after #, the Safari removes the fragment.

There are some documentation about this in :

http://news.qooxdoo.org/http-redirects-and-loss-of-fragment-identifiers

The question know how to handle this # problem with Safari.

Thank’s for the help

Posted at Nginx Forum:

Yo don’t need to escape the “!” if you delimit the URL with single
quotes…

"Hello,

Francis D. asked you several times to check the access.log file (you
should not find the fragment part in there).
oscaretu and I told you browsers don’t send the fragment part of an URL.

The problem isn’t from nginx nor the browser: it’s a normal behavior.

Best Regards"

In deed there was no information in access.log, the only information i
published was from error.log with nginx debug mode and an error 302 is
not a
error. It’s not an Nginx problem it’s a Safari problem.

Best Regards

Posted at Nginx Forum: