Apache 301 redirect and Mediawiki Short URLs

Any gurus out there? :)

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 www.domain.name redirects you to domain.name

go to www.domain.name/wiki/article redirects you to domain.name/wiki/w/index.php/article

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

Try this.

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. :D

Thanks, but I noticed something that might not work well with this?

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/

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct