Eliminating index.php from the url: Difference between revisions

From Meta, a Wikimedia project coordination wiki
Content deleted Content added
m Reverted changes by 2803:9800:988D:761B:7493:BF6F:E836:FF61 (talk) to last version by Johannnes89
Tag: Rollback
 
(37 intermediate revisions by 27 users not shown)
Line 1: Line 1:
{{MovedToMediaWiki|Manual:Short URL}}
<- [[MediaWiki User's Guide]]

{{Template:Sprotected}}

The page describes the steps needed to set up MediaWiki to use URLs without "index.php".

For example:

From:

'''<nowiki>http://mywiki.site.tld/wiki/wiki/index.php?title=Article_name</nowiki>'''

To:

'''<nowiki>http://mywiki.site.tld/wiki/Article_name</nowiki>'''

To eliminate even the "wiki" part, see [[Using a very short URL]].

==Getting URLs like those on Wikimedia sites==

This method will put articles under:

<nowiki>www.mysite.com/wiki/articlename</nowiki>,
and everything else under:

<nowiki>www.mysite.com/w/index.php?whatever</nowiki>,

...just like the WikiMedia sites.

Replace <nowiki>www.mysite.com</nowiki> and /filesystem/path/to/my/site to suit your site.

===Using aliases in httpd.conf===

This is the prefered method from a performance point of view, but requires access to edit httpd.conf; unfortunately, such access is unlikely in a shared hosting environment. It has been tested successfully with MediaWiki 1.4.4.

1. In LocalSettings.php, make sure you are using these default values:

$wgScriptPath = "/w";
$wgScript = "$wgScriptPath/index.php"

If you put the wiki installation in a subdirectory such as /w, use $wgScriptPath = "/w" as appropriate.

If you put the files (such as index.php) in the root, you can use $wgScriptPath = "" in LocalSettings.php.

2. In LocalSettings.php, set the following:

$wgArticlePath = "/wiki/$1";

'''Remember, the virtual directory for the wiki article space should never, ever overlap or hide real files. In particular it should never, ever overlap your base installation directory or the root directory. It can be a virtual subdirectory, such as /wiki.''' (For example: do not try to rewrite "<tt>/wiki/Article</tt>" to "<tt>/wiki/index.php?title=Article</tt>).

3. Set up the following alias in your Apache httpd.conf. It can be in a <code>&lt;VirtualHost&gt;</code> section or in your general site config. In this alias, the prefix <code>/filesystem/path/to/my/site</code> represents the path you installed to &mdash; the directory where MediaWiki's <code>index.php</code> lives. Replace the prefix as appropriate for your actual file system path.

#These must come last, and in this order!
Alias /wiki /filesystem/path/to/my/site/index.php
Alias /index.php /filesystem/path/to/my/site/index.php

After making modifications to httpd.conf, you might have to restart Apache to apply the changes.

If you are using Apache 2, you might also need to turn on <code>[http://httpd.apache.org/docs-2.0/mod/core.html AcceptPathInfo]</code>. It is on by default in a standard installation of Apache and PHP, but some vendors/packagers may have it disabled on your system.

===Using a rewrite rule in a .htaccess file===
This method may be useful if you have the ability to use rewrite rules in .htaccess but don't have conf access. But this method is more work for the httpd.
# install mediawiki in the dir for www.mysite.com/w as normal (using the installer)
# set <code>$wgArticlePath = "/wiki/$1";</code> in LocalSettings.php
# put a htaccess file with the following content in the dir for www.mysite.com
# close the php security hole...
# not actually needed but probably a good idea anyway
php_flag register_globals off
# first, enable the processing - Unless your ISP has it enabled
# already. That might cause weird errors.
RewriteEngine on
# uncomment this rule if you want Apache to redirect from www.mysite.com/ to
# www.mysite.com/wiki/Main_Page
# RewriteRule ^/$ /wiki/Main_Page [R]
# do the rewrite
RewriteRule ^wiki/?(.*)$ /w/index.php?title=$1 [L,QSA]

In httpd.conf this line must be added/uncommented:
LoadModule rewrite_module modules/mod_rewrite.so

Make sure Apache loads the Rewrite module.

====Moving mediawiki to another directory====
If you didn't follow the instructions and installed MediaWiki in the directory for www.mysite.com/wiki, then you will need to move it to another directory, such as "w". You will need to change the various paths (such as <tt>$IP</tt>) in <tt>LocalSettings.php</tt> to the new location.
====Purging cache====

If you notice that your changes to <code>$wgArticlePath</code> in LocalSettings.php are not being reflected in mysite.com/wiki/Main_Page, it may be due MediaWiki's caching of the links according to previous settings.

Go to mysite.com/wiki/Main_Page?action=purge to force MediaWiki to regenerate the cached links.

Also you can:
# execute the MySQL query "DELETE FROM objectcache;", or
# set <tt>$wgCacheEpoch</tt> to the current date.

== Troubleshooting ==
If you get internal server errors or similar, check out the Apache error.log. This usually has some clues about the reasons.

== See also ==
* [[MediaWiki i18n]] Localize/ customize things like the 'fromwikipedia' string
* [[MediaWiki User's Guide]]
See [[Talk:Eliminating index.php from the url|the talk page]] for more information on setting up non root rewrite rules.

Next page: [[PHP config]] >

[[Category:MediaWiki User's Guide]]

Latest revision as of 10:53, 22 January 2024