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.
Antihost offers Linux VPS plans with full root access, unlimited traffic on a 1 Gbps port and a 14-day free trial.
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.
That means both sides must agree:
- The server must route the public article path to the MediaWiki entry point.
LocalSettings.phpmust 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.
#1 Best Overall
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:
$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:
Rank #2
- Used Book in Good Condition
$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.
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
- Confirm that the rule is in the virtual host or permitted
.htaccesscontext. - Check the configuration for syntax errors using the validation method provided by your Apache installation.
- Reload or gracefully restart Apache so the new rule is active.
- Open a known page such as
/wiki/Main_Pageand 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.
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:
Rank #4
$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
- Put the
location /wiki/block inside the correctserverblock. - Validate the nginx configuration with your normal configuration-test command.
- Reload nginx.
- 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.
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_Pageloads 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.
Best Value
- Used Book in Good Condition
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.
$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.
Quick Recap
Reference configurations and documentation
- Manual: Short URL/LocalSettings.php — variables and path layout.
- Manual: Short URL/Apache — Apache routing and rewrite behavior.
- Manual: Short URL/Nginx — nginx locations and rewrite examples.
- Manual: Short URL/wiki/Page Title — .htaccess — an Apache
.htaccess-oriented example. - Extension:UrlShortener — optional redirect-style short links.
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.




