Manual:Short URL/wiki.example.com/Page title--Enabling a wiki using Apache Rewrite
From MediaWiki.org
[edit] Subdomain
[edit] Enabling a wiki on the root URL, a secondary wiki, and a rails app using Apache Rewrite
This shows how to enable a wiki on the root URL, a secondary wiki on a descendant URL, and a rails app with clean structure.
Example URL structure
- Primary wiki - Main page
http://example.com/ http://example.com/wiki_main/index.php?title=Main_Page
- Primary wiki - Special:Recentchanges
http://example.com/Special:Recentchanges http://example.com/wiki_main/Special:Recentchanges http://example.com/wiki_main/index.php?title=Special:Recentchanges
- Secondary wiki - Main page
http://example.com/wiki_other/Main_Page http://example.com/wiki_other/index.php?title=Main_Page
- Secondary wiki - Special:Recentchanges
http://example.com/wiki_other/Special:Recentchanges http://example.com/wiki_other/index.php?title=Special:Recentchanges
- Rails application
http://example.com/weblog/ http://example.com/weblog/controller
Pertinent directory structure
web/
example_com/
cgi-bin/
htdocs/
.htaccess
weblog -> ../rails/public
weblog.html
wiki_main/
.htaccess
LocalSettings.php
[usual mediawiki files]
wiki_other/
.htaccess
LocalSettings.php
[usual mediawiki files]
rails/
blogapp/
.htaccess
app/
config/
db/
public/
vendor/
weblog is a symbolic link to /web/example_com/rails/blogapp/public.
Contents of /web/example_com/htdocs/.htaccess
Options FollowSymLinks
RewriteEngine On
# Hide Main_Page from URL
RewriteCond %{REQUEST_URI} ^/Main_Page
RewriteRule ^(.*) / [R,L]
# If the file is real, skip this rule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/wiki_main/
RewriteRule ^(.*) /wiki_main/index.php/$1 [L]
# http://example.com displays the front page of the primary wiki
RewriteRule ^$ /wiki_main/index.php/Main_Page [PT,L]
- Contents of /web/example_com/htdocs/wiki_main/.htaccess
- Contents of /web/example_com/htdocs/wiki_other/.htaccess
Options FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?title=$1 [L,QSA]
Modifications to /web/example_com/htdocs/wiki_main/LocalSettings.php
$wgArticlePath = "/$1";
Modifications to /web/example_com/htdocs/wiki_other/LocalSettings.php
$wgArticlePath = "$wgScriptPath/$1";
Contents of /web/example_com/htdocs/weblog.html
<!-- Append trailing slash - Apache sees http://example.com/weblog as http://example.com/weblog.html Anyone know a better way to do this? Seems to happen before the RewriteRule in .htaccess --> <html><head> <meta http-equiv="Refresh" content="0; url=http://example.com/weblog/" /> </head></html>

