Difference between revisions of "Setup friendly URLs for MediaWiki on Apache2"

From DiscordDigital Wiki
Jump to navigation Jump to search
Line 5: Line 5:
<h2>Modifying LocalSettings.php</h2>
<h2>Modifying LocalSettings.php</h2>
<p>We append following code to it:</p>
<p>We append following code to it:</p>
<pre>$wgArticlePath = "/$1";  
<syntaxhighlight lang="php" line='line'>
$wgArticlePath = "/$1";  
$wgUsePathInfo = true;  
$wgUsePathInfo = true;  
$wgGenerateThumbnailOnParse = false;</pre>
$wgGenerateThumbnailOnParse = false;
</syntaxhighlight>
<h2>Creating .htaccess</h2>
<h2>Creating .htaccess</h2>
<p>We need to create ".htaccess" on our web root of MediaWiki.</p>
<p>We need to create ".htaccess" on our web root of MediaWiki.</p>
<p>Make sure the apache server has mod_rewrite enabled.</p>
<p>Make sure the apache server has mod_rewrite enabled.</p>
<p>.htaccess:</p>
<p>.htaccess:</p>
<pre>
<syntaxhighlight lang="apacheconf" line='line'>
RewriteEngine On
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?title=$1 [NC,L,QSA]
RewriteRule ^(.*)$ index.php?title=$1 [NC,L,QSA]
</pre>
</syntaxhighlight>
<h2>Conclusion</h2>
<h2>Conclusion</h2>
<p>After we reload our page, we should land on /Main_Page which makes URLs a lot friendlier.</p>
<p>After we reload our page, we should land on /Main_Page which makes URLs a lot friendlier.</p>
[[Category:MediaWiki]]
[[Category:MediaWiki]]

Revision as of 23:04, 27 February 2021

Prologue

When setting up MediaWiki you'll quickly realize that pages use /index.php.
This can be annoying especially for search engines.
To fix this we can do following changes:

Modifying LocalSettings.php

We append following code to it:

1 $wgArticlePath = "/$1"; 
2 $wgUsePathInfo = true; 
3 $wgGenerateThumbnailOnParse = false;

Creating .htaccess

We need to create ".htaccess" on our web root of MediaWiki.

Make sure the apache server has mod_rewrite enabled.

.htaccess:

1 RewriteEngine On
2 RewriteCond %{REQUEST_FILENAME} !-f
3 RewriteCond %{REQUEST_FILENAME} !-d
4 RewriteRule ^(.*)$ index.php?title=$1 [NC,L,QSA]

Conclusion

After we reload our page, we should land on /Main_Page which makes URLs a lot friendlier.