Mediawiki URL redirect with .htaccess

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]

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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