Wiki - short url

From NoskeWiki
Jump to: navigation, search

About

NOTE: This page is a daughter page of: Wiki


In the context of MediaWiki, a "short URL" is enabling your MediaWiki to use an abbreviated URL. In my case:


Although it's supposed to be easy, I had problems with my web-hosting and it took me a long time to achieve this! On this page I've taken some notes on the process in case I have the same struggles again.


How To Setup Short URLs

The official manual on how to do this is here:


In a nutshell, you should be able to get Short URLs to work by adding a .htaccess file to your root and adding a few extra lines to LocalSetting.php. You can generate the text you need to enter at this helpful site: http://shorturls.redwerks.org/... simply enter the address of your MediaWiki (in my case was http://www.andrewnoske.com/w/)


Problems Encountered

I had heaps of problems getting it working. The problem I had: it worked for a while, but pages loaded much slower and underwent periods of "500 Internal server error". I'm pretty sure it was an issue with my web-hosting. I found changing the .htaccess can be very problematic, and can took ages to update. The last time I played with this was Sep 2013, shortly after a database rearrangement forced me to reload my whole wiki.

Here's some configurations I tried:

Setups I've Tried

SetUp 1: Suggested short URL with thumbnail handler config

This configuration: uses redworks suggested configuration (including "404 thumbnail handler config").

.htaccess

RewriteEngine On
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]
RewriteRule ^/?$ %{DOCUMENT_ROOT}/w/index.php [L]
 
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?w/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/w/thumb.php?f=$1&width=$2 [L,QSA,B]
 
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?w/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/w/thumb.php?f=$1&width=$2&archived=1 [L,QSA,B]
 
############################
# This code was generated from:
#   http://shorturls.redwerks.org/  (recommended by http://www.mediawiki.org/wiki/Manual:Short_URL)
#   ... and feed it "http://andrewnoske.com/w/"


LocalSettings.php add these lines:

$wgScriptPath = "/w";          # this line is probably there already.  
$wgScriptExtension = ".php";   # this line is probably there already.  

$wgArticlePath = "/wiki/$1";       # INCLUDE ONLY IF USING "SHORT URL" SYSTEM IN .HTACCESS
$wgUsePathInfo = true;             # INCLUDE ONLY IF USING "SHORT URL" SYSTEM IN .HTACCESS

$wgEnableUploads  = true;              # this line is probably there already.  
$wgGenerateThumbnailOnParse = false;   # INCLUDE ONLY IF USING "SHORT URL" SYSTEM IN .HTACCESS (and set to false if using "404 thumbnail handler config")

.. seemed to work but inconsistent.


SetUp 2: Suggested short URL setup without thumbnail handler

This configuration: uses redworks suggested configuration, but then unchecking the "404 thumbnail handler config" option.

.htaccess

RewriteEngine On
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]
RewriteRule ^/?$ %{DOCUMENT_ROOT}/w/index.php [L]
 
############################
# This code was generated from:
#   http://shorturls.redwerks.org/  (recommended by http://www.mediawiki.org/wiki/Manual:Short_URL)
#   ... and feed it "http://andrewnoske.com/w/"
#   ... with "Include 404 thumbnail handler config" unticked. Along with this change the LocalSettings.php should include:
#
#      $wgScriptPath = "/w";
#      $wgScriptExtension = ".php";
#      $wgArticlePath = "/wiki/$1";
#      $wgUsePathInfo = true;


LocalSettings.php add these lines:

$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true; 
 
$wgScriptPath = "/w";          # this line is probably there already.  
$wgScriptExtension = ".php";   # this line is probably there already.

.. seemed to work but inconsistent - suspect it's just web-hosting.


SetUp 3: Custom Setup with short urls without thumbnail handler and custom "index.php" redirect (CURRENT)

One issue I had is that I used to use the long URL, and I was worried that all my past links to "andrewnoske.com/wiki/index.php?title=Wiki" would no longer work - or get rdirected to "andrewnoske.com/wiki/Index.php" - where it would assume "Index.php" was an actual article. To get around this I added an extra line "RewriteRule ^/?wiki/index.php(/.*)?$ %{DOCUMENT_ROOT}/home/wiki_forwarder.php [L]" and wrote a PHP page which helps ensure that anyone I referred to the old URL gets redirected to the matching short url.

.htaccess

RewriteEngine On
# A custom php page I wrote which redirects old request to "/wiki/index.php?title=Page" to "/wiki/Page"
RewriteRule ^/?wiki/index.php(/.*)?$ %{DOCUMENT_ROOT}/home/wiki_forwarder.php [L]
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]
RewriteRule ^/?$ %{DOCUMENT_ROOT}/w/index.php [L]
 
############################
# This code was generated from:
#   http://shorturls.redwerks.org/  (recommended by http://www.mediawiki.org/wiki/Manual:Short_URL)
#   ... and feed it "http://andrewnoske.com/w/"
#   ... with "Include 404 thumbnail handler config" unticked. Along with this change the LocalSettings.php should include:
#
#      $wgScriptPath = "/w";
#      $wgScriptExtension = ".php";
#      $wgArticlePath = "/wiki/$1";
#      $wgUsePathInfo = true;


LocalSettings.php add these lines:

$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true; 
 
$wgScriptPath = "/w";          # this line is probably there already.  
$wgScriptExtension = ".php";   # this line is probably there already.


wiki_forwarder.php contents:

<?php
$redirect_location = 'Location: http://www.andrewnoske.com/wiki/'.$_GET['title'];
//echo $redirect_location;
header('Location: http://www.andrewnoske.com/wiki/'.$_GET['title']);
?>

.. it seems to work, so for now this is my current configuration. In addition to people who've linked to the old URLs, I'm hoping Google search engine spiders will see this and will update where to find my pages. Sadly it took me a long time to figure all this out, so I'm sure I've lost quite a bit of ranking in the downtime. Now I just pray it stays good.


SetUp 4: No short URLs - used to reset things

I've tried other settings for short URLs but had no luck. The big problem however is each time I modify .htaccess I have to wait ages, refreshing the page for the new rules to appear. For some reason I've found it helps to follow these instructions:

ErrorDocument 404 http://www.andrewnoske.com/notfound.htm
 
# Stupid as it seems, but it things go wrong, put this single line to the .htaccess then in order access:
#   http://andrewnoske.com/something_not_existing   ... will show page not found and works almost INSTANTLY
#   http://andrewnoske.com/index.php    .... may have to wait 2-6 mins ("Internal Server Error" at first)
#   http://andrewnoske.com/             .... as above although hopefully not as LONG!
# Now modify your .htaccess file again and cross fingers.


Conclusion

I've had Short URLs work for a while, but it made things so slow it was almost impossible to upload images and I have changed ".htaccess" and then had to wait and wait so many times I've given up. I might ask my web-hosting what's causing the issue, but for now it seems like I'm forced to use the ugly long URLS with their "index.php?title=" in the middle.

It seems there isn't too much problem just renaming the directory from "/w/" to "/wiki", so long as you change the appropriate LocalSettings flags.


Links