Manual:Short URL/wiki/Page title -- PHP as a CGI module, no root access

From MediaWiki.org

Jump to: navigation, search

This solution pertains to people who may be running PHP as a CGI module. The best way to tell if you're using PHP as a CGI module is to go to your Special:Version page. If your PHP is marked like PHP 5.2.4 (cgi), you're at the right guide. It also uses a real MediaWiki installation as an example. Look for anything called "wiki." You should replace that with the name of your installation directory (folder).

Usually, the installation directory is both a folder within the public_html directory of a shared server (without root access) and a subdomain, but it is not necessary that you have the folder set up as a subdomain to get this to work.

You should keep in mind that this directory is second-level, meaning that it is installed directly into the folder mentioned. The structure of the installation used as an example here is as follows:

home/user/public_html/wiki.

You'll need to access two files for this solution:

  • LocalSettings.php
  • .htaccess (located in the web root, not the wiki install directory)

[edit] In LocalSettings.php

## If using PHP as a CGI module, use the ugly URLs
$wgScriptPath      = "/wiki";
$wgScript           = "$wgScriptPath/index.php";
$wgRedirectScript   = "$wgScriptPath/redirect.php";
 
$wgArticlePath      = "$wgScriptPath/$1";

If your installation is in the same directory such as http://webdesignwiki.phrax.com and not a sub-folder!

## If using php 5.2.4 (cgi) Currently default on 1and1
$wgScriptPath      = "";
$wgScript           = "$wgScriptPath/index.php";
$wgRedirectScript   = "$wgScriptPath/redirect.php";
 
$wgArticlePath      = "$wgScriptPath/$1";

[edit] In .htaccess

Make sure you are editing the .htaccess file in the web root, not the wiki install directory.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^wiki/(.+)$ /wiki/index.php?title=$1 [L,QSA]

But possible editing the .htaccess in the wiki directory with following content:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?title=$1 [L,QSA]

Note: if you're running some dumb server that needs .php5 extensions to run scripts at PHP 5, then you need to change the entries above. Remove "wiki" if your wiki is in DocumentRoot.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?title=$1 [L,QSA]

For users on http://www.1and1.com shared hosting using php5.2.4(CGI) add the following to your .htaccess file:

AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php

Note of a 1and1 user with PHP 5.2.5:

In the example above (with wiki in DocumentRoot), I had to replace

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

by

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

(note the removed /).

End of note of a 1and1 user with PHP 5.2.5.


Then check the following:

  • Go to your Wiki's installation directly by typing it in your browser's address bar. Do NOT refresh an article page or similar. Does the page load properly with short URLs, or is it infinitely redirecting? (If it is infinitely redirecting, make sure you have replaced all instances of "wiki" above with your directory, and that you do NOT have any values defined PRIOR to any portion of that value being defined.)
  • Does your CSS load properly? (If not, make sure the StylePath and StyleDirectory paths are correct in LocalSettings.php.)
  • Check your older articles. You may find that their articles are pointing to an incorrect directory. (The only solution I've found for this is to edit the page -you don't actually have to make any changes- and then save. Emptying your cache after that tends to ensure that you're viewing the right version of the page that points to the proper directory, short URLs and all.)

I hope this solution helps! If anyone has any questions, comments, or suggestions, please add them here (if it pertains to this specific solution!)

  • (new user, sorry if I don't get the niceties straight here) I found that the Edit link/tab on my old pages still contained index.php in the editing URL, and so when I tried to update a page mediawiki didn't find it... and I was given a new empty page. Did I miss something? I'm using 1.11
Personal tools