Manual:Short URL/wiki.example.com/Page title--Subdomain using mod-rewrite

From MediaWiki.org
Jump to: navigation, search

[edit] Subdomain with no Subdirectory in Article URL using mod-rewrite

Apache's mod-rewrite can be used to allow the shortest URL's of just http://yourdomain/pagename. Mod-rewrite changes the illegally formatted "friendly" URL request into a legitimate request directed at the index.php script like usual. To use mod-rewrite, specify a condition pattern, and a transformation rule to apply to the URL if it matches the condition pattern, such as in the following example:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/w.*/
    RewriteRule ^(.*) /wiki/index.php/$1 [L]

This re-write condition says not to touch any URL's which start with a lowercase W and start and finish with a forward slash, this protects all old-style article requests, and requests to internal MediaWiki files like scripts or images. By not specifically using the term wiki in the condition allows other directories of web documents outside the wiki such as /www/media

The re-write rule then assumes everything after the leading slash to be an article name and reformats the URL accordingly. Also change LocalSettings.php to set

$wgArticlePath = "/$1"

This is necessary to make the friendly form the default way of rendering links. Links involving a query-string will use the usual format.

This uses the technique for evading the Manual:Short URL#Ampersand (&) problem described below.

[edit] AnotherVariant - wiki.site.net/MainPage

Neither variant mentioned there worked for me, so I used my knowledge of LAMP to make it tick.

You've just setup documentation-only site, no other is or will be sitting there. So, there's no need for ugly /wiki/ in URL.

I suppose, you have working apache instalation. Modify those files accordingly, all files are in your website docroot.

To clarify: make sure you have the .htaccess file in your subdomain folder and not in the root. In this example you would need to have the .htaccess file in the wiki folder of site.net

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

LocalSettings.php

$wgArticlePath = "/$1";
$wgUsePathInfo = true;

robots.txt

User-agent: *
Disallow: /engine/
Disallow: /Special:Search
Disallow: /Special:Random

favicon.ico place your icon there

Done :) Because rewrite script is checking for existing files, both robots and favicon are served as suposed.

Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox