October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Enable Short URLs in MediaWiki with Apache or nginx

Set up MediaWiki short URLs by aligning $wgScriptPath and $wgArticlePath with Apache or nginx routing, then test assets, links, and redirect behavior.
WorldMediaWiki with Apache or nginx Length7 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To change MediaWiki article links from /w/index.php?title=Main_Page to /wiki/Main_Page, configure two layers together: your web server must route /wiki/ requests to MediaWiki’s index.php, and LocalSettings.php must tell MediaWiki to generate that public path. The usual layout keeps the application in /w while publishing articles beneath /wiki/. Apache uses mod_rewrite (or an allowed .htaccess file); nginx uses a location and rewrite rule.

What MediaWiki short URLs actually do

Short URLs do not replace MediaWiki’s front controller. The web server aliases a readable request such as /wiki/Main_Page to MediaWiki’s /w/index.php, and MediaWiki parses the page name. This is the approach described in the official Apache manual: “The goal here is to alias paths to /index.php and then let MediaWiki itself take care of parsing and routing the URL, based on the configuration in LocalSettings.php.”

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

That means both sides must agree:

  • The server must route the public article path to the MediaWiki entry point.
  • LocalSettings.php must generate links using the same public path.

If only one layer is changed, links may continue to contain index.php?title=, or requests may produce 404 errors, redirect loops, or internal errors.

Choose the URL layout before editing anything

The official examples assume this arrangement:

Role Path Purpose
MediaWiki application /w Contains index.php and the MediaWiki files.
Public article URLs /wiki/Page_title Readable URLs generated for wiki pages.

Replace these paths if your installation uses a different directory. The application path and article path must not accidentally be identical: /w is where the software is served, while /wiki/ is the public route that the server forwards to it.

Before changing routing, make a backup of LocalSettings.php and your active Apache or nginx configuration. You need administrative access to the virtual host for server-level rules. On shared hosting, you can use .htaccess only when the host permits overrides.

Set the MediaWiki URL variables

Edit the LocalSettings.php file in your MediaWiki installation and set the values that match the layout above:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
$wgScriptPath = "/w";
$wgArticlePath = "/wiki/$1";

$wgScriptPath identifies the URL path to MediaWiki’s main script. $wgArticlePath controls the path used for generated internal article links; $1 is replaced by the page name.

Some PHP and web-server combinations need path-info handling. If requests redirect repeatedly or the server does not expose the path information MediaWiki expects, add:

$wgUsePathInfo = true;

Use this setting when troubleshooting a loop or path-info failure rather than adding query strings to the rewrite rule. The variable descriptions and layout examples are documented in MediaWiki’s Short URL LocalSettings.php manual.

Configure Apache

Enable rewriting

Apache must have mod_rewrite available. Add the rules in the relevant virtual-host configuration, or use a .htaccess file in the web root above /w when AllowOverride permits it. The exact placement depends on how the site is hosted; the routing logic is the same.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use the article-path rule

A representative configuration from the MediaWiki Apache guide is:

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

The first two conditions leave existing files and directories alone, so static assets and real directories are not sent through the article rewrite. The first rule catches requests beginning with /wiki/ and sends them to MediaWiki’s entry point. The final rule handles the root or other unmatched entry requests according to the example deployment.

Keep the destination pointed at index.php. Do not change it to a rule that appends ?title=$1; MediaWiki should parse the page name from the path using the settings in LocalSettings.php.

Apply the Apache change

  1. Confirm that the rule is in the virtual host or permitted .htaccess context.
  2. Check the configuration for syntax errors using the validation method provided by your Apache installation.
  3. Reload or gracefully restart Apache so the new rule is active.
  4. Open a known page such as /wiki/Main_Page and check that it resolves without a redirect loop.

On shared hosting, a rule can appear correct but still do nothing when AllowOverride is disabled. In that case, the host administrator must enable the required override settings or install the rule in the virtual-host configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Configure nginx

Add the article location

In the nginx server block, add a location that forwards the public article path to MediaWiki:

location /wiki/ {
    rewrite ^/wiki/(?<pagename>.*)$ /w/index.php;
}

This captures the portion after /wiki/ as pagename and routes the request to /w/index.php. Keep the matching MediaWiki settings:

$wgScriptPath = "/w";
$wgArticlePath = "/wiki/$1";

The official nginx manual also shows locations for the entry point, assets, REST requests, the favicon, and the site root. Adapt those sections to the rest of your deployment rather than copying a complete server block blindly; existing static-file and PHP handling must continue to work.

Apply and verify the nginx change

  1. Put the location /wiki/ block inside the correct server block.
  2. Validate the nginx configuration with your normal configuration-test command.
  3. Reload nginx.
  4. Request /wiki/Main_Page, follow an internal link, and verify that images, stylesheets, and scripts still load.

Do not create a second public route that bypasses the configured application path. The article location should lead to MediaWiki’s entry point, while the rest of the server block continues to serve assets and other endpoints as configured for your installation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Test the finished setup

Test from a clean browser session or with a direct request so a cached redirect does not hide a configuration error.

  • Known article: /wiki/Main_Page loads the page rather than returning 404 or a server error.
  • Generated links: links inside the page use /wiki/Page_title, not /w/index.php?title=Page_title.
  • Assets: CSS, JavaScript, images, and the favicon continue to load from their expected paths.
  • Application entry: direct access to the configured MediaWiki application path still works.
  • Existing files: Apache’s file and directory exclusions prevent real assets from being rewritten as articles.
  • Administration and special pages: log in and open a representative special or edit page to ensure routing is not limited to the main page.

If the browser shows a redirect loop or an internal error, inspect the web-server error log and the PHP/MediaWiki log, then verify that the public /wiki/ path and application /w path are distinct and consistent in every setting.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common failures and fixes

Symptom Likely cause What to check
Links still contain index.php?title= MediaWiki is still generating its old article path. Confirm $wgArticlePath = "/wiki/$1"; is in the active LocalSettings.php, with no later setting overriding it.
/wiki/Main_Page returns 404 The server rule is missing, inactive, or in the wrong configuration scope. Check that mod_rewrite is enabled for Apache, or that the nginx location is inside the active server block; then reload the server.
Redirect loop detected Path-info handling or the application/public paths do not match. Try $wgUsePathInfo = true;, confirm $wgScriptPath is /w, and ensure the rewrite target is /w/index.php, not /wiki/.
Images or CSS fail after enabling short URLs Static files are being rewritten, or asset paths no longer match the deployment. For Apache, retain the !-f and !-d conditions. For nginx, review the asset locations alongside the article location.
Apache .htaccess has no effect Overrides are disabled by the hosting configuration. Move the rule to the virtual-host configuration or ask the host to permit the required override context.
Internal server error after editing A syntax error or unsupported directive was introduced. Run the server’s configuration test, inspect logs, and restore the backup while correcting one change at a time.

Apache and nginx: which setup is different?

Configuration concern Apache nginx
Routing mechanism mod_rewrite rules in a virtual host or permitted .htaccess. location plus rewrite in the server block.
Shared-hosting option Possible through .htaccess when AllowOverride permits it. Usually requires access to the nginx server configuration.
Existing files Use RewriteCond %{REQUEST_FILENAME} !-f and !-d before the article rule. Keep asset and other locations correctly defined alongside /wiki/.
Activation Reload or gracefully restart Apache. Reload nginx after validating the configuration.
MediaWiki variables $wgScriptPath = "/w"; and $wgArticlePath = "/wiki/$1";; add $wgUsePathInfo = true; if the server/PHP mode requires it.

The desired public URL is the same on either server. Only the routing syntax, configuration access, and reload process differ.

Short article URLs are not the UrlShortener extension

Replacing /w/index.php?title=Page with /wiki/Page is built-in URL routing and does not require an extension. Extension:UrlShortener is a separate, optional feature for redirect-style links, such as a configured template:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
$wgUrlShortenerTemplate = '/r/$1';

That extension can also use a custom $wgUrlShortenerServer. Very short custom paths require mod_rewrite or an equivalent server mechanism, but installing it is unnecessary when your goal is simply the conventional /wiki/Page_title article path.

Reference configurations and documentation

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.