Topic on Project:Support desk

Rewrite MediaWiki's URLs - Remove index.php

16
Mhuartamendia (talkcontribs)

I've just deployed an internal wikipage for my company. As of now we have a couple of sections on the left navigation pane (we have more but only three are being used at the moment).

Section 1 Section 2 Section 3

Whenever I click on one of the sections I get the URL:

http://mediawiki.my.domain/mediawiki/index.php/Section 1

What we desire to do is to get URL: http://mediawiki.my.domain/mediawiki/Section 1

Please, don't instruct me to read: https://www.mediawiki.org/wiki/Manual:Short_URL, the guide might be clear for you guys but at least for me, it isn't. A real life scenario example would make things a LOT easier...but there aren't any available, not even outside their wikipage. I've also read similar threads here on stack overflow, but still, no luck.

According to what I've been reading, file LocalSettings.php should have at the end:

 ## 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 please see:
 ## http://www.mediawiki.org/wiki/Manual:Short_URL
 $wgScriptPath = "/mediawiki";
 $wgScriptExtension = ".php";
 $wgArticlePath = "{$wgScriptPath}/wiki/$1";
 $wgUsePathInfo = true

But there has to be an htaccess file also on the mediawiki web directory with something like this:

RewriteEngine On
 RewriteRule ^/?mediawiki/wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]
 RewriteRule ^/mediawiki*$ %{DOCUMENT_ROOT}/w/index.php [L]*

So if I create this file on the mediawiki directory, will this work? any other information I might be missing here?

Bawolff (talkcontribs)

Based on what you've been describing (You desire http://mediawiki.my.domain/mediawiki/ArticleNameHere . index.php is in the mediawiki directory), you need a couple of differences: $wgArticlePath = "mediawiki/$1"; for the article path instead of what you wrote (rest of LocalSettings.php is fine).

and for the .htaccess you want

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?mediawiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]

At least I think. I haven't tested this, ymmv. The .htaccess may depend on what webserver and if its configured to read .htaccess files.

Mhuartamendia (talkcontribs)

Hey @Bawolff

Thanks for answering!


I'll try this in a moment, web server is Apache and I'm not really sure where to put the file. Should this be in /mediawiki path? or in the webserver main root path?

Mhuartamendia (talkcontribs)

@Bawolff


I edited local httpd.conf file to AllowOverride All, so .htaccess could have permissions to change the URL.

I also created the .htaccess file in /var/www/html with the content provided. However when browsing to http://mediawiki.my.domain/mediawiki, page is blank :(


Also edited LocalSettings.php as you said


Any ideas?

Mhuartamendia (talkcontribs)

Also, at this point, I don't know if .htaccess has to be placed at /var/www/html or the media wiki path...

Malyacko (talkcontribs)
Mhuartamendia (talkcontribs)

Hi @Malyacko


I understand these questions are more suitable for HTTPD/Apache, but we are not even sure if the code:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d RewriteRule ^/?mediawiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]

is correct.


Can you personally confirm that so I can move on to Apache/HTTPD Forums? Because if the code is wrong, there's no use on checking Apache

Bawolff (talkcontribs)

note those rewritecond rules are apache code not mediawiki code. I personally think its in scope here as configuring apache to work with mediawiki short urls is a common system admin task, and one lots of people have trouble with, but ultimately that is an apache question not a mediawiki question

Mhuartamendia (talkcontribs)

UPDATE:

Used this on Local Settings:


$wgScriptPath = "/mediawiki";

$wgArticlePath = "/mediawiki/$1";

And used this on .htaccess

RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^mediawiki/(.*)$ w/index.php?title=$1 [PT,L,QSA]

RewriteRule ^mediawiki/*$ w/index.php [L,QSA]

RewriteRule ^mediawiki$ w/index.php [L,QSA]


It is now redirecting ok, but stating MainPage is not found on directory

Þjarkur (talkcontribs)

I'm not quite sure what your last problem is regarding, but this tool can create automatic configurations.

Bawolff (talkcontribs)

in fairness you didn't mention in your otiginal post that mediawiki was in a directory named w.

Mhuartamendia (talkcontribs)

Hi @Bawolff

Actually that tool serves me right if the domain is public and it currently isn't

MediaWiki directory is in /mediawiki. Pretty sure that has something to do with it

Mhuartamendia (talkcontribs)

UPDATE: So I change my LocalSettings.php content to:


$wgScriptPath = "/mediawiki";

$wgArticlePath = "/mediawiki/$1";


And .htaccess to:


RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^mediawiki/(.*)$ mediawiki/index.php?title=$1 [PT,L,QSA]

RewriteRule ^mediawiki/*$ mediawiki/index.php [L,QSA]

RewriteRule ^mediawiki$ mediawiki/index.php [L,QSA]


Replacing all /w to mediawiki as it is the directory where it is installed


When I browse to http://mediawiki.my.domain/mediawiki I get:

Not Found

The requested URL /mediawiki/Main_Page was not found on this server.


Looks like rewriting works fine but there's no content now... (and there previously was)

Mhuartamendia (talkcontribs)

htaccess had to be on root path not mediawiki path, that was it! Thanks!

Simuako (talkcontribs)

may i know what do u mean by root path? i am facing your not found issue.

84.205.231.40 (talkcontribs)

the root path is usually "public_html" folder, it is the base directory where the webpage files are put.

Reply to "Rewrite MediaWiki's URLs - Remove index.php"