Search code examples
apache.htaccessmediawikino-www

htaccess conflicting with MediaWiki htaccess


I have the following code in my htaccess file:

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^wiki/(.*)$ /index.php?title=$1 [PT,L,QSA]
RewriteRule ^wiki/*$ /index.php [L,QSA]
RewriteRule ^wiki$ /index.php [L,QSA]

This shorten the URL from http://example.com/w/index.php?title=Page_title to example.com/wiki/Page_title.

I would also like to redirect example.com to www.example.com, but I am not sure on how I should implement this into the existing htaccess code without conflicting with other rules.

How can this be done?


Solution

  • RIght under RewriteBase /, add:

    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R]