I'm trying to detect mobile browsers, and redirect them, using detectmobilebrowsers.com. I'm using the script as an external includes as follows:
location /w/mobile/test/ {
set $mobile_rewrite do_not_perform;
include detect_mobile.conf;
echo $mobile_rewrite;
if ($mobile_rewrite = do_not_perform) {
# echo "should not hit";
rewrite ^/w/mobile/test/(.*) /w/test/$1 redirect;
break;
}
try_files /templates/public-test/ /templates/public-test/mobile.html =404;
}
location = /w/mobile/test {
set $mobile_rewrite do_not_perform;
include detect_mobile.conf;
if ($mobile_rewrite = do_not_perform) {
rewrite ^/w/mobile/test/(.*) /w/test/$1 redirect;
break;
}
try_files /templates/public-test/mobile.html =404;
}
This is working - so when I visit /mobile from a desktop, it will correctly redirect. Unfortunately, when I now view /mobile/... from a mobile browser, it gives me a 404.
I've used the echo module and found that the try_files in the upper location block is the problem - changing it to a rewrite works perfectly fine.
The weirder thing is, I implemented the exact same code, except I check $mobile_rewrite = perform instead of the do_not_perform for the desktop -> mobile redirect, and it's working perfectly fine.
The error returned by the error.log is as follows, when visiting /w/mobile/test/\<redacted\:
\<root_directory_location_redacted>/w/mobile/test/redacted" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /w/mobile/test/redacted HTTP/1.1", host: "localhost:8080"
Does anyone have any idea what the issue might be?
Aucun commentaire:
Enregistrer un commentaire