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

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 201.12.178.33 (Talk); changed back to last version by Woozle)
m (→‎Overview: updated title)
 
(58 intermediate revisions by 30 users not shown)
Line 3: Line 3:
 
==Overview==
 
==Overview==
 
The most reliable method seems to be the mod_rewrite, which requires access to either httpd.conf or requires particular handling options for .htaccess to be switched on (fortunately, they usually seem to be). Failing that, another method is:
 
The most reliable method seems to be the mod_rewrite, which requires access to either httpd.conf or requires particular handling options for .htaccess to be switched on (fortunately, they usually seem to be). Failing that, another method is:
* [[using error handlers to tidy MediaWiki URLs]]
+
* [[/error handlers]] - bad idea, don't use this
 +
 
 +
Some additional methods are documented in the [[#links]], below.
  
Some additional methods are documented [http://meta.wikimedia.org/wiki/Eliminating_index.php_from_the_url here].
 
 
==Using mod_rewrite==
 
==Using mod_rewrite==
 
This is probably documented elsewhere, but this is what actually worked on a shared server without root access or a shell.
 
This is probably documented elsewhere, but this is what actually worked on a shared server without root access or a shell.
 
This assumes MediaWiki is installed in the root of the www pages, e.g. <nowiki>http://thedomain.com/Main_Page</nowiki> is the wiki's main page.
 
  
 
First, the .htaccess file needs to include:
 
First, the .htaccess file needs to include:
Line 23: Line 22:
  
 
Second, modify LocalSettings.php:
 
Second, modify LocalSettings.php:
:$wgArticlePath     = "/$1";
+
:$wgScriptPath = '';
 +
:wgArticlePath = $wgScriptPath.'/$1';
 +
 
 +
This assumes MediaWiki is installed in the root of the www pages, e.g. <nowiki>http://yourdomain.com/Main_Page</nowiki> is the wiki's main page; if you have it in a subfolder, e.g. <nowiki>http://yourdomain.com/wiki/Main_Page</nowiki>, then:
 +
 
 +
:$wgScriptPath = '/wiki';
  
 
Then do ?action=purge on any page to test it. Internal links on existing pages will convert to the new URLs any time they are saved or purged.
 
Then do ?action=purge on any page to test it. Internal links on existing pages will convert to the new URLs any time they are saved or purged.
  
The above seems to work for everything (including editing) without breaking old-style URLs, and may offer clues as to how to fix the minor problems which make the 404 method (below) unusable.
+
The above seems to work for everything (including editing) without breaking old-style URLs.
  
 
This method is also documented here, with some minor changes: http://wiki.welldesignedurls.org/Clean_Urls_for_MediaWiki
 
This method is also documented here, with some minor changes: http://wiki.welldesignedurls.org/Clean_Urls_for_MediaWiki
Line 34: Line 38:
 
* proper handling of page named [[.htaccess]] (click on that for a demonstration of the problem)
 
* proper handling of page named [[.htaccess]] (click on that for a demonstration of the problem)
 
* ability to have the wiki installed in a subdirectory while still making it appear to be in the domain's root folder
 
* ability to have the wiki installed in a subdirectory while still making it appear to be in the domain's root folder
 +
 
==Comments==
 
==Comments==
 
Please feel free to post comments here or on the Talk page if you try any of these procedures.
 
Please feel free to post comments here or on the Talk page if you try any of these procedures.
Line 40: Line 45:
 
6/23/2007: I used your .htaccess and then set ''$wgArticlePath = "$wgScriptPath/$1";''. This way the forwarding works regardless of what directory the wiki is located in. In my case it was ''/wiki''. --Jordan Mendler ({{email|jmendler|ucla|edu}})
 
6/23/2007: I used your .htaccess and then set ''$wgArticlePath = "$wgScriptPath/$1";''. This way the forwarding works regardless of what directory the wiki is located in. In my case it was ''/wiki''. --Jordan Mendler ({{email|jmendler|ucla|edu}})
 
-------------------------
 
-------------------------
 +
12/02/2007: Method worked fine, using Jordan Mendler's modification to allow for my ''/wiki'' subdirectory. You should post this on mediawiki's [http://www.mediawiki.org/wiki/Manual:Short_URL Manual:Short URL] page, as they do not have this solution listed and it seems simpler and possibly less bug-prone then other methods. --Adam Burley (AKA Bilby) (bilbyATdigitalcaveDOTorg)
 +
-------------------------
 +
2007-12-02 MW 1.11 seems to do something which breaks log-ins using the above method. I solved this once, but I'm not sure which specific change made the difference. Here's part of the LocalSettings from a MW 1.11 installation where logins work fine:
 +
<php>
 +
## The URL base path to the directory containing the wiki;
 +
## defaults for all runtime URL paths are based off of this.
 +
$wgScriptPath      = "";
 +
$wgScriptExtension  = ".php";
 +
 +
# standard Woozle MW customizations
 +
$wgScript          = "$wgScriptPath/index.php";
 +
$wgArticlePath      = "/$1";
 +
$wgUsePathInfo = false;
 +
</php>
 +
 +
==Links==
 +
* <s>[[metawikipedia:Eliminating index.php from the url|Eliminating index.php from the url]]</s> moved/consolidated
 +
* [[mwsite:Manual:Short URL|Manual:Short URL]]
 +
* [http://wiki.welldesignedurls.org/Clean_Urls_for_MediaWiki Clean URLs for MediaWiki]

Latest revision as of 22:53, 14 December 2017

Navigation

computing: software: web: MediaWiki: customization: shortening MediaWiki URLs

Overview

The most reliable method seems to be the mod_rewrite, which requires access to either httpd.conf or requires particular handling options for .htaccess to be switched on (fortunately, they usually seem to be). Failing that, another method is:

Some additional methods are documented in the #links, below.

Using mod_rewrite

This is probably documented elsewhere, but this is what actually worked on a shared server without root access or a shell.

First, the .htaccess file needs to include:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

Second, modify LocalSettings.php:

$wgScriptPath = ;
wgArticlePath = $wgScriptPath.'/$1';

This assumes MediaWiki is installed in the root of the www pages, e.g. http://yourdomain.com/Main_Page is the wiki's main page; if you have it in a subfolder, e.g. http://yourdomain.com/wiki/Main_Page, then:

$wgScriptPath = '/wiki';

Then do ?action=purge on any page to test it. Internal links on existing pages will convert to the new URLs any time they are saved or purged.

The above seems to work for everything (including editing) without breaking old-style URLs.

This method is also documented here, with some minor changes: http://wiki.welldesignedurls.org/Clean_Urls_for_MediaWiki

Wish list:

  • proper handling of page named .htaccess (click on that for a demonstration of the problem)
  • ability to have the wiki installed in a subdirectory while still making it appear to be in the domain's root folder

Comments

Please feel free to post comments here or on the Talk page if you try any of these procedures.


6/23/2007: I used your .htaccess and then set $wgArticlePath = "$wgScriptPath/$1";. This way the forwarding works regardless of what directory the wiki is located in. In my case it was /wiki. --Jordan Mendler (jmendlerspam@spamuclaspam.spamedu)


12/02/2007: Method worked fine, using Jordan Mendler's modification to allow for my /wiki subdirectory. You should post this on mediawiki's Manual:Short URL page, as they do not have this solution listed and it seems simpler and possibly less bug-prone then other methods. --Adam Burley (AKA Bilby) (bilbyATdigitalcaveDOTorg)


2007-12-02 MW 1.11 seems to do something which breaks log-ins using the above method. I solved this once, but I'm not sure which specific change made the difference. Here's part of the LocalSettings from a MW 1.11 installation where logins work fine: <php>

    1. The URL base path to the directory containing the wiki;
    2. defaults for all runtime URL paths are based off of this.

$wgScriptPath = ""; $wgScriptExtension = ".php";

  1. standard Woozle MW customizations

$wgScript = "$wgScriptPath/index.php"; $wgArticlePath = "/$1"; $wgUsePathInfo = false; </php>

Links