Apache 301 redirect and Mediawiki Short URLs
I have my Mediawiki setup fine for short urls, so that index.php and all that are hidden when articles are viewed. However, I noticed that www. was still working and I don't want it to, so I put this in one of my apache conf files:
RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
This works brilliantly when you go to the root part of my domain, but if you go to an article in the www. domain, it redirects you to the long url version.
i.e.:
go to
go to
Any of this make sense to anyone? Somehow it totally breaks the short urls in Mediawiki. I don't think it will be very common for someone to use the www. for anything but the page page (and this redirects fine), but it's still weird.
2 Replies
RewriteEngine On
RewriteRule ^wiki/(.*)$ /(path to wiki)/index.php?title=$1 [PT,L,QSA]
RewriteRule ^wiki/*$ /(path to wiki)/index.php [L,QSA]
Tell me how it works.
Here's all the relevant info in the file for this domain (will the Alias statements clash with what you typed?):
RewriteEngine on
DirectoryIndex index.php
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !^wiki/extensions/*
RewriteCond %{REQUEST_URI} !^w/extensions/*
Alias /w/index.php /var/www/w/index.php
Alias /wiki /var/www/w/index.php
Alias /index.php /var/www/w/index.php
Alias /w/skins/ /var/www/w/skins/
Alias /w/extensions/ /var/www/w/extensions/