Simplest way to get MediaWiki to require HTTPS on all pages?

user1258361 picture user1258361 · Jun 12, 2012 · Viewed 17k times · Source

I need a MediaWiki installation to require the use of https (and reject normal http). I've spent 2 hours looking. Setting $wgServer doesn't work and closing port 80 in httpd.conf doesn't work either.

My wiki installation is run on an Apache server.

Answer

We Are All Monica picture We Are All Monica · Jun 12, 2012

My answer assumes that you already have Apache listening for https traffic on port 443. If that's not the case, you need to set that up first. The procedure will be different depending on what operating system you are running.


You want to do this in Apache. On my Ubuntu system, there's a file /etc/apache2/ports.conf which contains the following line:

Listen 80

You will have a similar config file that contains that line. Delete it, and don't forget to restart Apache.


Another way to accomplish this, which allows for more complex Apache configurations where you allow HTTP access to some parts of the site, is to use a .htaccess file in your MediaWiki directory. Try this:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}