diff --git a/roles/archwiki/templates/LocalSettings.php.j2 b/roles/archwiki/templates/LocalSettings.php.j2 index 4cd3e4b3907dca3d5bb62f4f8d80ed5974a4c7b8..2076aa753930c18cef278d1a1253947098b4f95b 100644 --- a/roles/archwiki/templates/LocalSettings.php.j2 +++ b/roles/archwiki/templates/LocalSettings.php.j2 @@ -61,3 +61,13 @@ $wgMemCachedServers = [ "unix://{{ archwiki_memcached_socket }}:0" ]; # security headers $wgReferrerPolicy = ["no-referrer-when-downgrade"]; $wgEditPageFrameOptions = "DENY"; + +## The URL base path to the directory containing the wiki; +## defaults for all runtime URL paths are based off of this. +## For more information on customizing the URLs +## (like /w/index.php/Page_title to /wiki/Page_title) please see: +## https://www.mediawiki.org/wiki/Manual:Short_URL +$wgScriptPath = ""; +$wgArticlePath = "/title/$1"; +# $wgUsePathInfo is not necessary: https://github.com/wikimedia/mediawiki/blob/bb92c4d1acc029eed0f6848360dff5b2436695fc/includes/WebRequest.php#L151-L153 +#$wgUsePathInfo = true; diff --git a/roles/archwiki/templates/nginx.d.conf.j2 b/roles/archwiki/templates/nginx.d.conf.j2 index 53036c1ed96d96d5c5c85e99ad292de055e6c815..26c4992db3a4a81bf3b964e706dfda273a82030b 100644 --- a/roles/archwiki/templates/nginx.d.conf.j2 +++ b/roles/archwiki/templates/nginx.d.conf.j2 @@ -52,20 +52,19 @@ server { deny all; } - # special case due to our '/index.php/Main_Page' type URLs - location ~ ^/(?:index|redirect)\.php(?:/.*)$ { - access_log /var/log/nginx/{{ archwiki_domain }}/access.log main; - access_log /var/log/nginx/{{ archwiki_domain }}/access.log.json json_main; - fastcgi_pass archwiki; - fastcgi_index index.php; - fastcgi_split_path_info ^(.+\.php)(.*)$; - if (!-f $document_root$fastcgi_script_name) { - return 404; - } - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_param HTTPS on; - include fastcgi_params; + # Redirect old URLs to the new short-url (/title/) + location ~ ^/index.php/(.*)$ { + return 307 /title/$1; + } + + # Handling for the article path (pretty URLs) + location ^~ /title/ { + rewrite ^ /index.php; + } + + # Handling for MediaWiki REST API, see https://www.mediawiki.org/wiki/API:REST_API + location ^~ /rest.php/ { + rewrite ^ /rest.php; } # special case for '/load.php' type URLs to cache css/js in nginx to relieve php-fpm @@ -74,11 +73,7 @@ server { access_log /var/log/nginx/{{ archwiki_domain }}/access.log.json json_main; fastcgi_pass archwiki; fastcgi_index index.php; - fastcgi_split_path_info ^(.+\.php)(.*)$; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_param HTTPS on; - include fastcgi_params; + include fastcgi.conf; fastcgi_cache wiki; fastcgi_cache_valid 200 10m; @@ -88,16 +83,12 @@ server { # normal PHP FastCGI handler location ~ ^/[^/]+\.php$ { + try_files $uri =404; access_log /var/log/nginx/{{ archwiki_domain }}/access.log main; access_log /var/log/nginx/{{ archwiki_domain }}/access.log.json json_main; fastcgi_pass archwiki; fastcgi_index index.php; - if (!-f $document_root$fastcgi_script_name) { - return 404; - } - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param HTTPS on; - include fastcgi_params; + include fastcgi.conf; } # whitelist known OK directories