Reputation: 41
I'm trying to set up a mediawiki site with short URLs and SSL enabled. I've been trying for some time now and this is my setup:
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/w/index.php [L]
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The code enables SSL, however the problem is that every insecure link is redirected to main page, rather than its https counterpart.
E.g going to: wiki.com/article redirects to https://wiki.com/main_page rather than https://wiki.com/article
I can not configure apache, so htaccess is my only solution. Any ideas?
Upvotes: 1
Views: 518
Reputation: 41
I figured it out. The solution is rather simple - I had to display the https rules first.
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/w/index.php [L]
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]
Upvotes: 1