Mediawiki URL redirect with .htaccess

Posted April 12, 2015 6.7k views

I use Mediawiki on my site’s subdomain (viki). I changed my url structure.

Old url structure:

New url structure:

I just deleted “/index.php/” from url.

I want to redirect old urls to news on .htaccess. (I use Apache) How i redirect old URL to new?

I tried that but doesnt work:

RewriteEngine On 
RewriteBase / 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^viki/(.*)$ /index.php?title=$1 [PT,L,QSA] 
RewriteRule ^viki/*$ /index.php [L,QSA] 
RewriteRule ^viki$ /index.php [L,QSA] 
RewriteRule ^index.php/(.*)$ /$1 [R=301,L]

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

I do not believe that the MediaWiki one-click image has the Apache rewrite module enabled by default so there are a couple changes that are needed to have apache use a redirect setup configured in an .htaccess file.

1.) Enable the module with the command

a2enmod rewrite

2.) In your virtualhost configuration file in /etc/apache2/sites-enabled find the “AllowOverride” setting for your main directory and change “AllowOverride None” to “AllowOverride All”, this allows configuration variables in your .htaccess file to override your virutalhost defaults.

3.) Restart apache for the changes to take effect with the command:

service apache2 restart