I'm running a multilingual wiki (MediaWiki 1.26.2 with MobileFrontend) on nginx 1.9.3/OpenBSD 5.8.
For each language wiki, I have a separate MediaWiki installation folder and a subdomain like en.domain.com pointing to that folder.
I'd like to add a subdomain like en.m.domain.com for the mobile view using the MediaWiki installation folder of the desktop view but with an appended &mobileaction=toggle_view_mobile
(or ?mobileaction=toggle_view_mobile
with a question mark instead of an ampersand if there is already an argument).
I'm also using CORS, short URLs and redirects from http://
to https://
.
This is how my server block looks like:
server {
listen 80;
server_name en.m.domain.com;
root /path/to/domain/en;
index index.html index.htm index.php;
autoindex off;
# CORS
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'X-Requested-With, Accept, Content-Type, Origin';
# Redirect to https://
if ($http_cf_visitor ~ '{"scheme":"http"}') {
return 301 https://$server_name$request_uri;
}
location = / {
return 301 https://en.m.domain.com/wiki/Main_Page;
}
location = /w {
return 301 https://en.m.domain.com/wiki/Main_Page;
}
location = /w/ {
return 301 https://en.m.domain.com/wiki/Main_Page;
}
location = /wiki {
return 301 https://en.m.domain.com/wiki/Main_Page;
}
location = /wiki/ {
return 301 https://en.m.domain.com/wiki/Main_Page;
}
# Short URLs
location / {
index index.php;
error_page 404 = @mediawiki;
}
location @mediawiki {
rewrite ^/wiki([^?]*)(?:\?(.*))? /w/index.php?title=$1&$2 last;
}
location ~ \.php5?$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass 127.0.0.1:1234;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
location ~ \.php?$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass 127.0.0.1:1234;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
# Append mobileaction=toggle_view_mobile for mobile version
location / {
# If there are no arguments add a question mark
if ($args = '') {
set $new_request_uri "$request_uri?mobileaction=toggle_view_mobile";
}
# If there are already arguments add an ampersand
if ($args != "") {
set $new_request_uri "$request_uri&mobileaction=toggle_view_mobile";
}
rewrite $new_request_uri last;
}
}
Unfortunately the mobileaction=toggle_view_mobile
part doesn't work :(
Any ideas how to fix this?
Thanks and cheers,
Till