Help:Setting up client-side redirects

This does not appear to have worked since some time circa 2011.


It is possible to set up MediaWiki to force client-side redirects (using HTTP 302, "temporary redirect"). Doing this means redirects will be handled by the client's browser instead of by the server.

What?
This piece of code forces all redirects to be done by the client, by issuing them a 302 Temporary Redirect to the new pages specific location.
Why?
A lot of search engines decrease your pages rank if they discover duplicated content. The traditional Redirect method allows a huge amount of duplication, and doesn't redirect as nicely. This also allows you to use images for navigation. Additionally it can be a limitation/annoying to not see the full redirected pages location in the address bar, and having the annoying "Redirected from" link.

Since modifying MediaWiki's functions like done in the method mentioned above could break some extensions using them like Polyglot, you should better use the following little extension:

	<?php
	$wgHooks['InitializeArticleMaybeRedirect'][] = 'redirectHook';
	
	function redirectHook($title, $request, &$ignoreRedirect, &$target, &$article)
	{
		if (!$ignoreRedirect && $article->isRedirect()) {
			if (($target = $article->followRedirect()) instanceof Title) {
				$target = $target->getFullURL();
			}
		}
		return true;
	}