MediaWiki configuration - strange redirect behaviour after form POST

MediaWiki configuration - strange redirect behaviour after form POST - .htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, php, redirects, mediawiki, .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :


I've recently setup a wiki using MediaWiki but am having the toughest time getting the ShortURL configuration working properly (for example, so that pages appear as Main_Page instead of index.php?title=Main_Page. It's installed inside a subfolder of a subdomain (e.g. http://intranet.example.com/mediawiki/), and at present my .htaccess file in this mediawiki folder has the following lines (I've created this file, it's not shipped with MediaWiki):



RewriteEngine On
RewriteCond %REQUEST_URI ^/mediawiki/.*$
RewriteCond %REQUEST_URI !^/mediawiki/index.php.*$
RewriteCond %REQUEST_URI !^/mediawiki/load.php.*$
RewriteCond %REQUEST_URI !^/mediawiki/skins/.*$
RewriteRule ^(.*)$ index.php/$1 [L]


And the LocalSettings.php has the following lines which affect the routing of page requests:



$wgScriptPath      = "/mediawiki";
$wgScriptExtension = ".php";
$wgArticlePath = "/mediawiki/$1";
$wgUsePathInfo = true;
$wgServer = "http://intranet.example.com/";


I've tried experimenting with these options, removing and adding slashes in different places to try and find the best working configuration and for the most-part it's all working as you might expect, apart from the redirects that happen following a form post (e.g. after logging in/out or editing a page).



In these circumstances the user is redirected every time to http://intranet.example.com//mediawiki/Main_Page, even when Main_Page is not the current page being worked on (very frustrating) and notice the extra forward slash? This causes an HTTP 404 error.



On an edit page the form post action URL is /mediawiki/index.php?title=Main_Page&action=submit, which looks fine to me. The issue seems to be with the internal redirect that happens after the processing is complete as the page changes do save properly.



I don't know if it gives any clues but I notice from the generated source that the stylesheets and javascript links begin with http://intranet.example.com//mediawiki/load.php?... with that second forward slash reappearing again (though these resources still load fine somehow).



As far as I can tell I've followed the MediaWiki official installation and configuration instructions correctly. Any help appreciated! It's obviously not robust enough with its current behaviour. Non-tech users aren't going to know they need to edit the URL after every time the redirect breaks!






If I remove the starting forward slash from $wgArticlePath then requesting http://intranet.example.com/mediawiki/ leads to the following redirects in my apache log:



"GET /mediawiki/ HTTP/1.1" 301 -
"GET /mediawiki/mediawiki/Main_Page HTTP/1.1" 301 -
"GET /mediawiki/mediawiki/mediawiki/Mediawiki/Main_Page HTTP/1.1" 301 -
"GET /mediawiki/mediawiki/mediawiki/Mediawiki/mediawiki/Mediawiki/mediawiki/Mediawiki/Main_Page HTTP/1.1" 301 -


and so on until eventually I get a "Bad title" WikiPedia page returned to the browser.


Solution :

The solution now working and tested - in the LocalSettings.php file, shared in case anyone else has trouble with this:



$wgScriptPath      = "/mediawiki";
$wgScriptExtension = ".php";
$wgArticlePath = "/mediawiki/$1";
$wgUsePathInfo = true;
$wgServer = "http://intranet.example.com";


The problem was caused by a forward slash on the end of the $wgServer parameter.


Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect