Manual talk:Short URL/wiki.example.com/Page title--Subdomain with no Subdirectory in Article URL
From MediaWiki.org
I wanted direct requests to the Main_Page when the URL was "" or "/". My directory structure is a bit redundant, but it's:
/var/www
/var/www/mediawiki
/var/www/mediawiki/wiki
I used this vhost to do the desired redirects. Also note that I changed the main redirect specified on this page to ignore the leading slash as it wasn't passing the correct content to index.php:
<VirtualHost *:80 *:443 >
ServerName wiki.YOURDOMAIN..com
DocumentRoot "/var/www/mediawiki"
RewriteEngine On
#allow fetching of css, js and the like
RewriteRule ^/(W|w)iki/skins/([a-z]+)/(.+)$ /wiki/skins/$2/$3 [L]
#allow fetching of fave icon
RewriteRule ^/favicon.ico$ /wiki/favicon.ico [L]
# get home page requests to Main_Page
RewriteRule ^(\/*)$ /wiki/index.php?title=Main_Page [L]
# all other requests go to specific page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\/*)(.*)$ /wiki/index.php?title=$2 [L,QSA]
</VirtualHost>
- The downside to using your "get home page requests to Main_Page" is that (at least for me), it doesn't rewrite to wiki.example.com/Main_Page, it actually shows Main_Page as wiki.example.com/, which means there's two URLs to Main_Page (very bad for search!). I'd tried using RedirectPermanent / /Main_Page but that caused a loop of adding Main_Page to the url forever. --IBulk 19:01, 18 November 2008 (UTC)
[edit] .htaccess suggestion
Hi, this guide works great. Just a small suggestion that it's useful to have the line
# anything that contains a dot without a colon should be left alone RewriteRule ^[^:]*\. - [L]
at the start of the 'normal' .htaccess file as well as the internationalised version as this allows browsers & search engines to access eg favicon.ico and robots.txt without being redirected to a wiki page. So the full final .htaccess file reads as below:
RewriteEngine On
RewriteRule ^[^:]*\. - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) /index.php?title=$1 [L,QSA]