Difference between revisions of "MediaWiki/archive/customizing/URLs/error handlers"

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Jump to navigation Jump to search
m (Reverted edits by 61.135.134.67 (Talk); changed back to last version by Woozle)
Line 1: Line 1:
 +
[http://shulend.hostinggratisvenezuela.com/articles/university-of/ university of british columbia] [http://www12.asphost4free.com/catlongtail/resources/watching-wife/ watching wife] [http://squealingpiglet.w8w.pl/content/mayra/ mayra] [http://shulend.hostinggratisvenezuela.com/articles/anons/ anons] [http://reobhecc.hostinggratisusa.com/resources/wwii/ wwii] [http://www12.asphost4free.com/catlongtail/resources/ben-stein/ ben stein] [http://utgang.hostinggratisuruguay.com/view/free-tattoo.html free tattoo patterns] [http://virgietyus.profil.bz/wrought-iron.htm wrought iron kitchen carts] [http://squealingpiglet.w8w.pl/content/cellulite-cure/ cellulite cure] [http://janisdunham.profil.bz/blog/m-and-d-mower.html m and d mower part] [http://janisdunham.profil.bz/blog/asslicking.html asslicking] [http://utgang.hostinggratisuruguay.com/view/preteen-models.html preteen models pics] [http://virgietyus.profil.bz/career-site-search.htm career site search] [http://www12.asphost4free.com/zossia/girl-love.html girl love pedophilia] [http://tabethacaudill.profil.bz/small/stupid-pics.html stupid pics] [http://janisdunham.profil.bz/blog/weddings-dresses.html weddings dresses] [http://utgang.hostinggratisuruguay.com/view/charter-a.html charter a luxury yacht] [http://dinatregre.profil.bz/chippendales.html chippendales] [http://skquek.2day.biz/description/teen-websites.html teen websites] [http://recycledphrase3.orgfree.com/resources/police-standoff/ police standoff swat] [http://beamcneese.profil.bz/1024x768.html 1024x768] [http://utgang.hostinggratisuruguay.com/view/application-cell.html application cell free phone] [http://recycledphrase3.orgfree.com/resources/hannity/ hannity] [http://lipkaya-loj.678host.com/free-cumshot.html free cumshot mpegs] [http://recycledphrase3.orgfree.com/resources/free-teen/ free teen web cams] [http://www12.asphost4free.com/zossia/asian-golden.html asian golden shower] [http://recycledphrase3.orgfree.com/resources/south-bay/ south bay real estate] [http://www12.asphost4free.com/denisem/new/crime-scene/ crime scene investigation] [http://sukinsa.hostinggratisvenezuela.com/resources/jay-frost.html jay frost] [http://reobhecc.hostinggratisusa.com/resources/professional-networking/ professional networking events] [http://sukinsa.hostinggratisvenezuela.com/resources/sarah-jessica.html sarah jessica parker] [http://janisdunham.profil.bz/blog/tits-movies-free.html tits movies free] [http://skquek.2day.biz/description/swedish-blond.html swedish blond models] [http://squealingpiglet.w8w.pl/content/san-diego/ san diego cabinet shops] [http://recycledphrase3.orgfree.com/resources/nude-mature/ nude mature women] [http://recycledphrase3.orgfree.com/resources/limo-rentals/ limo rentals] [http://squealingpiglet.w8w.pl/content/nude-boy/ nude boy art] [http://squealingpiglet.w8w.pl/content/homemade-clip/ homemade clip] [http://virgietyus.profil.bz/spit.htm spit] [http://recycledphrase3.orgfree.com/resources/furi-kuri/ furi kuri] [http://www12.asphost4free.com/catlongtail/resources/pakistan/ pakistan] [http://sweetestdrop.678host.com/content/card.html card] [http://squealingpiglet.w8w.pl/content/nude-sports/ nude sports women] [http://bugubudji.myxhost.com/text/sublime-directory.html sublime directory adult] [http://margenemerriam.profil.bz/topic/best-gourmet-coffee.html best gourmet coffee] [http://www12.asphost4free.com/zossia/hedwigs-theme.html hedwigs theme] [http://laruereagan.profil.bz/hard-body.html hard body] [http://janisdunham.profil.bz/blog/polycystic-ovaries.html polycystic ovaries] [http://recycledphrase3.orgfree.com/resources/poppy/ poppy] [http://utgang.hostinggratisuruguay.com/view/payday-advance.html payday advance loan] [http://janisdunham.profil.bz/blog/tax-rate-on-capital.html tax rate on capital gains] [http://lipkaya-loj.678host.com/against-same.html against same sex marriage] [http://shulend.hostinggratisvenezuela.com/articles/white-leather/ white leather belt mens] [http://skquek.2day.biz/description/travelpro-luggage.html travelpro luggage] [http://www12.asphost4free.com/denisem/new/virginia-warner/ virginia warner] [http://squealingpiglet.w8w.pl/content/illinois-state/ illinois state police] [http://recycledphrase3.orgfree.com/resources/mase-welcome/ mase welcome back] [http://mimiwise.profil.bz/description/paris-pussy.htm paris pussy] [http://mimiwise.profil.bz/description/perfect-woman.htm perfect woman] [http://dinatregre.profil.bz/chloroformed.html chloroformed superheroines] [http://sukinsa.hostinggratisvenezuela.com/resources/clit-stimulation.html clit stimulation] [http://beamcneese.profil.bz/wedding-photographers.html wedding photographers] [http://reobhecc.hostinggratisusa.com/resources/ballistics/ ballistics] [http://squealingpiglet.w8w.pl/content/austrian-newspapers/ austrian newspapers in english] [http://recycledphrase3.orgfree.com/resources/sulfur-analyzer/ sulfur analyzer] [http://recycledphrase3.orgfree.com/resources/detroit-strippers/ detroit strippers] [http://squealingpiglet.w8w.pl/content/drip-irrigation/ drip irrigation supplies] [http://squealingpiglet.w8w.pl/content/cb-radios/ cb radios] [http://beamcneese.profil.bz/medical-supply.html medical supply clinton maryland] [http://www12.asphost4free.com/denisem/new/medal-of/ medal of honor] [http://margenemerriam.profil.bz/topic/blaze-of-glory.html blaze of glory] [http://mimiwise.profil.bz/description/independence.htm independence day] [http://squealingpiglet.w8w.pl/content/california-health/ california health insurance plan] [http://squealingpiglet.w8w.pl/content/roswell-area/ roswell area 51] [http://www12.asphost4free.com/catlongtail/resources/albert-einstein/ albert einstein biography] [http://squealingpiglet.w8w.pl/content/paintball-fields/ paintball fields] [http://bugubudji.myxhost.com/text/australia-distributor.html australia distributor in toy] [http://laruereagan.profil.bz/graduation-friends.html graduation friends forever] [http://squealingpiglet.w8w.pl/content/lying-bastards/ lying bastards] [http://reobhecc.hostinggratisusa.com/resources/pcchips-motherboards/ pcchips motherboards] [http://www12.asphost4free.com/denisem/new/nitromethane/ nitromethane] [http://tabethacaudill.profil.bz/small/verizon-online.html verizon online] [http://www12.asphost4free.com/crumplstiltskin/lib/indian-teen.html indian teen] [http://recycledphrase3.orgfree.com/resources/shots/ shots] [http://reobhecc.hostinggratisusa.com/resources/covered-wagon/ covered wagon] [http://leannenowak.profil.bz/unicode-characters.html unicode characters in xml] [http://reobhecc.hostinggratisusa.com/resources/palliative-care/ palliative care ethics] [http://laruereagan.profil.bz/south-coast.html south coast casino] [http://virgietyus.profil.bz/rows-to-columns.htm rows to columns] [http://www12.asphost4free.com/zossia/elk-meat.html elk meat] [http://squealingpiglet.w8w.pl/content/kim-possible/ kim possible theme song] [http://skquek.2day.biz/description/performance-audio.html performance audio salt lake] [http://recycledphrase3.orgfree.com/resources/omaha-apartments/ omaha apartments] [http://leannenowak.profil.bz/callkelly.html callkelly] [http://mariettebickers.profil.bz/celebs-boobs.html celebs boobs] [http://squealingpiglet.w8w.pl/content/pharmacy-technician/ pharmacy technician salary] [http://dinatregre.profil.bz/the-effects-of.html the effects of radiation poisoning] [http://recycledphrase3.orgfree.com/resources/versailles/ versailles] [http://squealingpiglet.w8w.pl/content/cheap-glucophage/ cheap glucophage] [http://recycledphrase3.orgfree.com/resources/hentai-yaoi/ hentai yaoi]
 
==Navigation==
 
==Navigation==
 
{{web software|MediaWiki}}: [[MediaWiki customization|customization]]: [[shortening MediaWiki URLs]]: [[using error handlers to tidy MediaWiki URLs|using error handlers]]{{sidebar|__TOC__}}
 
{{web software|MediaWiki}}: [[MediaWiki customization|customization]]: [[shortening MediaWiki URLs]]: [[using error handlers to tidy MediaWiki URLs|using error handlers]]{{sidebar|__TOC__}}

Revision as of 00:12, 25 November 2007

university of british columbia watching wife mayra anons wwii ben stein free tattoo patterns wrought iron kitchen carts cellulite cure m and d mower part asslicking preteen models pics career site search girl love pedophilia stupid pics weddings dresses charter a luxury yacht chippendales teen websites police standoff swat 1024x768 application cell free phone hannity free cumshot mpegs free teen web cams asian golden shower south bay real estate crime scene investigation jay frost professional networking events sarah jessica parker tits movies free swedish blond models san diego cabinet shops nude mature women limo rentals nude boy art homemade clip spit furi kuri pakistan card nude sports women sublime directory adult best gourmet coffee hedwigs theme hard body polycystic ovaries poppy payday advance loan tax rate on capital gains against same sex marriage white leather belt mens travelpro luggage virginia warner illinois state police mase welcome back paris pussy perfect woman chloroformed superheroines clit stimulation wedding photographers ballistics austrian newspapers in english sulfur analyzer detroit strippers drip irrigation supplies cb radios medical supply clinton maryland medal of honor blaze of glory independence day california health insurance plan roswell area 51 albert einstein biography paintball fields australia distributor in toy graduation friends forever lying bastards pcchips motherboards nitromethane verizon online indian teen shots covered wagon unicode characters in xml palliative care ethics south coast casino rows to columns elk meat kim possible theme song performance audio salt lake omaha apartments callkelly celebs boobs pharmacy technician salary the effects of radiation poisoning versailles cheap glucophage hentai yaoi

Navigation

computing: software: web: MediaWiki: customization: shortening MediaWiki URLs: using error handlers

Overview

These methods set up the Apache web server so that MediaWiki pages are loaded in response to requests for pages which the web server sees as unavailable. Custom code extracts the page name from the request information, and calls MediaWiki functions to display the requested page.

I don't know of any particular circumstances where this would work and the recommended mod_rewrite method would not; this documentation is now considered obsolete, but is being kept here in case it is useful.

Potential problem: use wget to make sure that pages are not actually returning an error code (404 or 403), which apparently prevents some browsers (e.g. MSIE) from viewing them under some circumstances, and will certainly adversely affect search-engine listings.

Using a 404 Handler

At this point, I can't recommend this method unless nothing else works. If you try this method, please report back on how it goes. --Woozle 18:46, 29 June 2006 (EDT)

This uses the 404 (missing page) redirect mechanism – a standard /index.php/ request is handled by the standard code (in index.php), but any other URL which doesn't correspond to an existing page (within the wiki or not) is handled by a modified index.php. For any given "nonexistent" URL of the form "http://yourdomain.com/nonexistent/page", the code returns a wiki page entitled "Nonexistent/page", with the "nonexistent" URL displayed as the URL for that page.

There is also a feature wherein you can create a page called Mediawiki:your/url/here and it will redirect to an article whose title is the contents of that page. For example: http://wiki.vbz.net/Currentevents is redirected to vbzwiki:Current events because the page vbzwiki:MediaWiki:Currentevents contains the text "Current events". (This is a bit of a trivial trick, as you can accomplish almost the same thing using #redirect pages.)

First, in the main .htaccess file (or in httpd.conf if you prefer), assign a location to handle 404 errors such that a PHP file will be loaded -- either of these will do, for example:

ErrorDocument 404 /errors/404/
ErrorDocument 404 /wiki404error.php

In the first instance, your modified index.php file would go in /errors/404/; in the second, it would be renamed wiki4040error.php and go in the same folder as the normal index.php.

The remaining instructions depend on which MediaWiki version you are using.

Version 1.4

These instructions were made from changes that actually worked, but I may have left out some steps. I was more careful when I did the changes for version 1.5, so if these don't work check the version 1.5 instructions for anything missing.

Second: Make the changes indicated in the 404-handling copy of index.php:

if ( '' == $title && 'delete' != $action ) {
## 2005-06-19 Woozle mods for "missing" page
	# title not passed in parameter; use REQUEST_URI from environment
	$title = rawurldecode(ltrim($_SERVER['REQUEST_URI'], " /"));
	# see if there's a page designated for this URI
	$wgTitle = Title::newFromText( wfMsgForContent( $title ) );
	if ('' == $wgTitle) {
		$wgTitle = Title::newFromText( $title );
	}
## end Woozle mods
} elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
	/* redirect to canonical url, make it a 301 to allow caching */
	$wgOut->setSquidMaxage( 1200 );
# 2005-06-21 Woozle mods to allow 404 page to summon wiki page without redirecting
#	$wgOut->redirect( $wgTitle->getFullURL(), '301');
	$wgArticle = new Article( $wgTitle );
#  	$mainText = $wgOut->parse( $wgArticle->getContent( false ) );
#	echo $mainText;
	$wgArticle->view();
# end Woozle mods
} else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {

Version 1.5

Second: In the same folder as the modified index.php, create a LocalSettings.php with the following contents:

<?php
require_once( "../../LocalSettings.php" );

$wgScript           = $wgScriptPath;
$wgArticlePath      = "$wgScript/$1";
?>

Note: "../../LocalSettings.php" works if your modified index.php is buried two folders deep from your main index.php (as in the /errors/404/index.php example); adjust it as needed to point to your main LocalSettings.php.

Third: Make the changes indicated in the 404-handling copy of index.php:

  • First change - need to point to the copied Defines.php:
# 2005-10-25 Woozle - for 404 handling
require_once( './Defines.php' );
  • Second change - this is optional, but it cleans up the file a lot:
# 2005-10-25 Woozle - config code removed because it will never be executed
#if( !file_exists( 'LocalSettings.php' ) ) {
# ...
#}
  • Third change - this pulls in the title-request from the error URI:
# Query string fields
# 2005-10-25 Woozle - 404 support - parameters have to be parsed from $_SERVER instead of $_REQUEST
	$raw_uri = rawurldecode(ltrim($_SERVER['REQUEST_URI'], " /"));
	$arr_uri = explode('?',$raw_uri);
	$title = $arr_uri[0];
	$uri_qry= $arr_uri[1];
	parse_str($uri_qry,$_REQUEST);
	$action = $wgRequest->getVal( 'action', 'view' );
	$title_force = $wgRequest->getVal( 'title' );
	if ( != $title_force) {
		$title = $title_force;
	}
# 2005-10-25 END
  • Fourth change - optional and untested - allow title redirection
if (  == $title && 'delete' != $action ) {
	$wgTitle = Title::newFromText( wfMsgForContent( 'mainpage' ) );
# 2005-10-26 Woozle - 404 support - optional redirect based on "mediawiki:articlename"
	if ( == $wgTitle) {
		$wgTitle = Title::newFromText( $title );
	}
# 2005-10-26 END
  • Fifth change - I'm actually not sure if this is necessary, but don't have time to test uncommenting it:
# 2005-10-25 Woozle - for 404 handling - block out redirection code
# was -- if ((action is explicitly "view") AND (title is not passed as param) OR (title is not in canonical form) AND ??
#} else if ( ( $action == 'view' ) && 	(!isset( $_GET['title'] ) || $wgTitle->getPrefixedDBKey() != $_GET['title'] ) && !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
#{
#	/* redirect to canonical url, make it a 301 to allow caching */
#	$wgOut->setSquidMaxage( 1200 );
#	$wgOut->redirect( $wgTitle->getFullURL(), '301');
} else if ( NS_SPECIAL == $wgTitle->getNamespace() ) {

Finally

Finally, put the modified index.php where it will be the page used to handle 404 errors.

  • Caveats:
    • Your arbitrary URL will have its first character capitalized before it is displayed as the page's title or used to load another page (if you have set up a Mediawiki: page for it), although the URL shown will remain unchanged
    • There is probably a lot of excess index.php code which can be stripped out, as it will never be executed in this context
    • URLs ending in slashes appear to be a problem for some namespaces; the wiki code appears to be reading the URL from some place other than the modified code. (This doesn't seem to be a problem for version 1.5.)
    • All wiki links on the loaded page will point back to canonical wiki URLs, e.g. http://htyp.org/wiki/index.php/Main_Page; to change this. see "Shortening the links" below. 2006-02-16 This has been fixed.
    • Image thumbnail links don't work. 2006-02-16 This has been fixed.
  • 2006-02-16 Notes:
    • I changed the procedure a bit and page viewing now seems to work consistently, but I've only checked a few pages for proper behavior. Please test thoroughly before using on a production page, and let me know what you find.
    • Editing does not work properly
    • If certain pages persist in showing old-style links, they may be cached; add "?action=purge" to the URL to clear the cache for a given page. If you are working on an active site using the old-style links, some pages may mysteriously revert to old-style links as visitors browse them through the old-style portal, causing the old-style to be re-cached.
    • This method is probably not very compatible with most webstats generators, but I haven't tried it long enough to see what happens. Probably all pages will be logged as 404 errors, which isn't terribly useful.

Note about CPU load: Obviously it has to do the same URL translation it would normally have to do and then determine that the file doesn't exist, but that shouldn't take any more cycles than locating an existing file; for URLs containing at least one slash, it should be quicker. Given all the processing done by the MediaWiki software for loading "normal" wiki pages, I suspect the difference is negligible.

Using a 403 [forbidden] Handler

anonymous user 64.110.252.116 reports: Something I have found to work very well is to force all files except index.php to "Deny from All" and use a 403 error handler to push all requests to index.php:

An example .htaccess:

Deny from All
<Files "index.php">
   Allow from All
</Files>
# NOTE: DirectoryIndex may not be necessary
DirectoryIndex index.php
ErrorDocument 403 /index.php

This could probably be shortened up, but I have found it works great. :-) anonymous user 64.110.252.116

This would seem to be a variation on the 404 method above; not sure if there are any advantages or disadvantages to either one.