Short url

From DreamHost

Jump to: navigation, search
This article or section may require a cleanup.
We are hoping to create articles that meet certain standards. Please discuss this issue on the talk page. Editing help is available.


How to configure Dreamhost hosted MediaWiki to run on short URLs instead of the ugly long php URLs

In <mywikidir>/.htaccess file, so that incoming requests can be short url format, I have these Apache Rewrite rules:

# rewrite rules for Short URLs:
Options FollowSymLinks
RewriteEngine On
# prevent your Dreamhost /stats from breaking
# (see http://wiki.dreamhost.com/index.php/Mod_rewrite)
RewriteCond %{REQUEST_URI} ^/stats/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/failed_auth.html$
RewriteRule ^.*$ - [L]
# end of /stats fix
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Use this one if you are using *ugly URLs* -- PHP as CGI:
RewriteRule ^(.+)$ /index.php?title=$1 [L,QSA]
# Use this one if you are using *pretty URLs* -- PHP as Apache module:
#RewriteRule ^(.+)$ /index.php/$1 [L,QSA]



I'm using pretty URLs and the last line above wasn't working for me so I used this line instead:

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

(found here)Change wikidir to the name of the directory where your wiki is installed. --SimonDorfman 07:17, 31 May 2007 (PDT)



and this in <mywikidir>/LocalSettings.php so the generated pages will contain links in the short url format:

# Short URL stuff
# see http://meta.wikimedia.org/wiki/Using_a_very_short_URL
$wgArticlePath      = "/$1";


If you want your mediawiki to be set up like wikipedia etc, where the articles are at your.domain.tld/wiki/TOPIC_NAME etc.

Install your MediaWiki a folder "w" in your.domain.tld. i.e. your.domain.tld/w

then put the above .htaccess file into your.domain.tld (this will now be the only thing at the top of this structure, so you may want a php automatic forwarding page. Except, instead of using:

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

use

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

and in your LocalSettings.php, set the $wgArticlePath such that:

$wgArticlePath      = "/wiki/$1";

[| This article may help]

robots.txt

If you have implemented short urls so that wiki article links look like http://wikisite.tld/Articlename or http://wikisite.tld/wikidir/Articlename then please preserve bandwidth on your server -- prevent search engine spiders from crawling all your wiki's action pages (edit, history, discuss, etc.) by putting the following into a file named 'robots.txt' at the root of the site's web directory (/home/yourusername/sitename.org/robots.txt):

User-agent: *
Disallow: /index.php

if your urls look like http://wikisite.tld/wikidir/Articlename you can be more specific like this instead:

User-agent: *
Disallow: /wikidir/index.php

(Adjust wikidir to whatever your wiki directory is; leave it out if your wiki is the root directory of your site.)

Note that this will ban search engines from everything on your site that has /index.php or /wikidir/index.php in its path depending which of above you use. So if you have other PHP stuff running on that site/[dir/] location besides a MediaWiki with short urls, be awair of that.

robots.txt is only valid when located at the top level of your site (/home/yourusername/sitename.org/robots.txt).

See also

Personal tools