Manual talk:Short URL/Apache

About this board

References for the VisualEditor issue?

Dantman (talkcontribs)

There have been some recent changes to the recommended RewriteConfig rules implying that without them VisualEditor is broken.

Can anyone provide some reference to this issue and confirm that it's real and not just speculation added by some users?

The first change targets the VisualEditor user agent but the second asserts that it's just rest.php that needs to not be rewritten. However the RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f line is already supposed to be enough to stop Apache from rewriting rest.php (otherwise it would be rewriting index.php, thumb.php, etc). So this recommendation should be redundant.

I would like to know because if it's a real change we need to make to the recommended Short URL config, then I'd like to update the ShortURL Builder tool. And if it's not actually necessary for VisualEditor to work, then the modification to the page should be reverted.

Reply to "References for the VisualEditor issue?"

Missing information on some setups

Rdrg109 (talkcontribs)

I'm currently running MediaWiki in my personal computer for experimentation purposes (i.e. not planning to use it in production). I'm using Apache in Arch Linux and was able to get the short URL working.

I spent more than 4 hours trying out the solutions mentioned in this documentation. Namely, I created the file .htaccess in multiple locations, edited the options AllowOverride and Options as specified in this page, but none of these ways worked. I decided to give up on Apache and use nginx instead, since there's also documentation on how to get the Short URL for nginx.

However, I then found Short URL/Page title -- Windows & Apache without 403 on Special Pages and was able to find the solution that worked for me. My solution was to add the Rewrite rules under <Directory "/srv/http"> in the file /etc/httpd/conf/httpd.conf. As a complete beginner user of Apache, I'd like to know whether this is recommended or not so that I can add it in this manual since it is not mentioned.

I'll describe what worked for me with the hope that other users find a solution faster than me and don't have to spend as much hours as I spent doing trial and error.

1. First, I wanted my links not to have mediawiki in the URL. That is, the default configuration that is bundled in Arch Linux makes the URL of the articles have the following format.


but I wanted the pages to exist in


To do this, I changed the first line of /etc/webapps/mediawiki/httpd-mediawiki.conf from Alias /mediawiki "/usr/share/webapps/mediawiki" to Alias /w "/usr/share/webapps/mediawiki"

2. Uncomment the line #LoadModule rewrite_module modules/ in the file /etc/httpd/conf/httpd.conf

3. Add the RewriteEngine and RewriteRule instructions under the section <Directory "/srv/http"> in the file /etc/httpd/conf/httpd.conf (see code block below)

(omitted lines)

DocumentRoot "/srv/http"
<Directory "/srv/http">
    RewriteEngine On
    RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]

(omitted lines)

4. I then opened /usr/share/webapps/mediawiki/LocalSettings.php to make sure that the variables had the following values. By default, the variable $wgScriptPath already had that value, I just needed to add the line for $wgArticlePath below it.

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

5. Finally, I restarted the service.

$ systemctl restart httpd.service

At this point, I was able to visit the Main Page using the following URLs.

Ciencia Al Poder (talkcontribs)
Reply to "Missing information on some setups"

Short URL instructions for placing rewrite rule in Apache instead of .htaccess (for tech-morons like me)

School4schools (talkcontribs)

Took a while to figure this out, but here are my simpleton's instructions on how to place the re-write directly on Apache instead of using an .htaccess file.

My host is a Virtual Private Network (VPN) which means I have access to CPANEL and WHM

If you do not have access to WHM, this is not for you. Also, these steps are written for Windows users.

NOTE: even though the instructions here say to edit the httpd.conf file directly DO NOT EDIT IT. You will see that at the very bottom of the file it reads:

#  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


#  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

>> there is an editor function in WHM called "Include editor" I could not figure out how to use this, so I used the following steps instead. I'm sure this will drive knowledgeable users crazy, but this is how I managed to get this stupid rewrite on the server without having to use an .htacces file

>> before starting remove an existing .htaccess file and/or remove the commands for short url that may be in it.

>> we are going to give those instructions directly to the Apache server, which will be included in a file called httpd.conf We are NOT going to edit that file directly.

Step 1.

> Go to CPANEL and open File Manager

>> it should open at the /home/accountname/ directory.

>> if not, click on that directory on the left-hand menu of File Manger.

> click on "+ File" on the top menu (to add a file)

> enter a file name with the extension conf

>> any name works, but must have .conf as extension: as in filename.conf

> select that file and click on "Edit"

>> it will be blank. Add to the very top in plaint text, per instructions on this manual, this code:

RewriteEngine On



RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/w/index.php [L]

> "Save" and "Close" the file

Step 2.

> Go to WHM and open "Terminal"

> navigate to the httpd.conf file by using "change directory" commands (cd /)

>> the file should be located on this path: /etc/apache2/conf/

>>> first, navigate to the /etc/ folder by typing cd /etc

>>> then navigate to subfolders from there by typing cd directoryname (such as cd apache2 , then cd conf)

Step 3.

> once you are in the directory /etc/apache2/conf/

>> type dir in order to see the contents of that directory

>> you should see listed there the file htttp.conf

>>>> note that the instructions manual here says it may be called apache2.conf

(<<< btw, those instructions are confusing as it indicates that apache2.conf is a directory whereas it is a file name; in my WHM, which is up to date, it is http.conf )

> now we want to read that file:

> type cat http.conf

<<< "cat" command is for "read file"

>> the file contents will spill across the terminal

>> next, highlight the file contents on the screen using your mouse (start from the bottom, hit left click & hold it while scroll up to the beginning of the file, thus highlighting all the contents)

>>> release the left click button, then right click on the selected text and select "copy"

>>> paste the contents into a plain text editor (I use notepad.exe in Windows)

>>> in the text editor, search for your website name

>>> at the bottom the entry for your website/s it will read something like this:

"  # To customize this VirtualHost use an include file at the following location

  # Include "/etc/apache2/conf.d/userdata/ssl/2_4/accountname/domain/*.conf"

( >> NOTE: if you do not have SSL enabled it that directory will read /std/)

>>> your account name and domain will be already written in that path

> copy that directory path to a new text editor window

Summary so far:

  1. we created a new .conf file using CPANEL at the root of the CPANEL File Manager and wrote the re-write code for short urls.
  2. we identified the correct path to add that file to by reading in WHM terminal, the existing httpd.conf
  3. we copied that path and file name into a text editor.

Step 4.

> type cd to go back to the terminal root directory

>> it looks like [~]#

> now we are going to move the file you created in CPANEL to the location that the httpd.conf file told you to place it in order for whm to read and incorporate it into the existing httpd.conf file

> we will use the move command in the terminal: mv

> in your text editor type out the entire move command with the directory paths and file name

>> it should look like this (with your particular account and domain):

mv etc/apache2/conf.d/userdata/ssl/2_4/accountname/domain/filename.conf /etc/apache2/conf.d/userdata/ssl/2_4/accountname/domain/

<< note the single space after "mv" and "filename.conf" (so it reads mv[SPACE]/path/path/filename.conf[SPACE]/path/path

> hit enter

>> this will move the file to the directory that the httpd.conf file told you corresponds to your website

>> if a file with that name is already there, it will ask you to confirm overwriting it. If so, type YES

Step 5.

> now we need to ask Apache to read the file and recompile the httpd.conf fle

> go to the root directory on the terminal

> type /scripts/ensure_vhost_includes --all-users

>> Apache will recompile the httpd.conf file and tell you if this worked or not

Step 6.

> reboot the server

> use "Gentle reboot"

Test out your site and hopefully you're good to go!

(Sadly this does not fix my issue with Visual Editor, which stopped working after I moved to short urls. That would seem to be a problem for another day)

Reply to "Short URL instructions for placing rewrite rule in Apache instead of .htaccess (for tech-morons like me)"
Proshin Rodion (talkcontribs)

1. You need to ensure the rewrite module is loaded in apache2 by doing this:



then when prompted type


then press <enter>

Reply to "rewrite module"

This entire page is junk and needs deleting

10 (talkcontribs)

These are the worst instructions for anything I have ever encountered.

There are just seemingly random thoughts recorded in paragraphs. Files that are mentioned are:


/etc/apache2/sites-available/default.conf (this actually 000-default.conf on my distribution)

.htaccess (many places)


Which of these files should be edited?

What is needed are instructions like this:

  1. edit <filename> - add <this line> and <this line>
  2. enable mod_somemod by typing a2enmod <mod_somemod>
  3. restart apache2 by typing systemctl restart apache2


Ciencia Al Poder (talkcontribs)

What it needs is editing, not deleting. This is a wiki, so any edit that improves the content is welcome.

2001:44C8:4400:7766:E5CD:F711:321B:495C (talkcontribs)

@Ciencia Al Poder like the anonymous user above me (believe it or not that we are not the same person) I think that you take the seriously bad situation of this webpage and how serious it misleads people, too easy.

2001:44C8:4400:7766:E5CD:F711:321B:495C (talkcontribs)

@Jonathan3 indeed, I am not the anonymous who wrote the original post but I can understand where his frustration is coming from; you told me "it's all in here" but really, sadly it's not very much the case.

Jonathan3 (talkcontribs)

I bet if you think it through and stop asking questions you'll find the answer here :-)

2001:44C8:4512:B6D6:A16F:69E9:F0A3:8BD9 (talkcontribs)

@Jonathan3 I guess you meant my recent questions on the subject in "support desk";

I nicely disagree with that approach ; I when a page is SO undidactic, it kinds of take the spirit out from cooperating, for me at least. In face I already wrote a revised version of the opener of this "guide" and should publish it soon.

Polymath uk (talkcontribs)

I'm the anonymous user. I've remembered my user/pass.

For those running debian 10 (probably Ubuntu too) with root access and apache2 do all of this as root:

1. You need to ensure the rewrite module is loaded in apache2 by doing this:



then when prompted type


then press <enter>

2. Next, edit /etc/apache2/sites-available/000-default.conf by typing

nano /etc/apache2/sites-available/000-default.conf

(or your favourite editor like vi instead)

Immediately before the closing </VirtualHost> tag insert three lines that read:

RewriteEngine On

RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/index.php [L]

RewriteRule ^/*$ %{DOCUMENT_ROOT}/index.php [L]

This assumes that your mediawiki installation is in the same directory that apache2 is treating as the document root. The document root path is shown in the file you have open. If your index.php file is in that directory then this will work. This will be the case if your URLs are If your URLs look like then you will need to modify the above lines to look like this:

RewriteEngine On

RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/somefolder/index.php [L]

RewriteRule ^/*$ %{DOCUMENT_ROOT}/somefolder/index.php [L]

Save the file

3. restart apache2 by typing:

systemctl restart apache2

If it won't restart you've done something wrong which you need to troubleshoot.

4. Next edit LocalSettings.php by typing

nano /var/www/html/LocalSettings.php

(or whatever path you are using)

Look for the text $wgScriptPath (which will probably be near the top)

As above, if your installation is directly in document root, this will probably read $wgScriptPath = ""; in which case, leave it alone. If you are in a subdirectory like above, it will read something different. Leave it alone anyway.

Add this line under it:

$wgArticlePath = "/wiki/$1";

Save the file.


2A02:908:2057:7C80:4012:8145:F350:A140 (talkcontribs)

I used the script on, running wikipedia on a low-cost shared server. I copied the Apache Config and saved it as a new .htaccess in the directory that the URL should be redirected to, and changed the rows in LocalSetting.php. All done. This was just trial and error and I am happy it worked. (talkcontribs)

Thank you so much

the "somefolder" tip solved de problem for me

Why you do not put this in the actual article?

Polymath uk (talkcontribs)

I didn't realize I could edit the article!

Reply to "This entire page is junk and needs deleting"

Need some help with redirects in .htaccess

Summary by Berot3

didn't reply

Fredrilj (talkcontribs)

My problem is that both none HTTPS requests and requests with WWW redirects to main page, whitch is fine when the requested url is the root domain, but not if the request is an article, special page etc.

Example 1: redirects to, but I want to redirect to

Example 2: redirects to, but I want to redirect to

This is my settings in .htaccess:

<IfModule rewrite_module>
RewriteEngine On
Options +FollowSymlinks

# Redirect to Mydomain/wiki/Main_Page
RewriteCond %{HTTP_HOST} mydomain\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /wiki/$1 [PT,L]

# Short url for wiki pages
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [PT,L]

# Permanent redirect www url to non-www
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
RewriteRule (.*)$1 [L,R=301]

# Permanent redirect HTTP to HTTPS
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R=301,L]

Any idea what I'm doing wrong?

Fredrilj (talk) 10:22, 17 April 2017 (UTC)

Robertinventor (talkcontribs)

Probably that you need to put the http to https redirect at the start rather than the end of the file - I haven't studied how .htaccess works - but if https is working fine then if you convert the http to https right at the start, the rest of the url unchanged, then as it flows through it should work just as if the user had entered an https url originally. Robertinventor (talk) 16:52, 1 October 2018 (UTC)

Stevio Bee (talkcontribs)

Make sure the 'rewrite' module is on first - had me stuck for ages.... it is off by default on Apache

'sudo a2enmod rewrite'

then restart:

'sudo systemctl restart apache2'

Reply to "Need some help with redirects in .htaccess"

Added {{Outdated}} Template to flag major cleanup

DanShearer (talkcontribs)

Every few years I come to this page to implement short URLs, then remember it is horribly confusing and work it out again from scratch. As many people have pointed out, the content seems authoritative but is unlikely to work on any Apache installation. In addition to being incorrect, it is also confusing. So let's start.

One of the first things is to split up Alias from Rewrite techniques into separate sections. Pretty sure the commenter here is correct in saying that Apache recommend Alias over Rewrite although I don't know a reference for that. So the Alias version should probably be listed first.

There are some working or almost-working recipes on this talk page to give us a start.

DanShearer (talk) 22:14, 18 November 2021 (UTC)

2003:DE:F743:E8FF:149C:39B2:C753:C9C9 (talkcontribs)

So it was wrong in multiple ways to blame myself for failing on this short URL task. Thank you @DanShearer for posting here and thanks even more for picking up the adventure to rewrite the page from scratch. --Paddy F. from G.

DanShearer (talkcontribs)

Thanks Paddy. I could probably make a bigger difference in a few minutes, except I don't know how to edit with the translation tags. Is there a tool that makes that easy?

Ciencia Al Poder (talkcontribs)

You can edit without adding any translation tags, and someone with knowledge will add them when you're done

DanShearer (talkcontribs)

I hardly know where to start, but I've done a bit of poking around. If someone wants to do a lot of deleting that would be good.

Dantman (talkcontribs)

Alias version should not be listed first, it shouldn't even be here at all. Alias should not be used. I've never seen the reference for Apache recommending Alias over RewriteEngine. But I have a feeling that if it exists at all it's a generic recommendation that is being mis-applied to MediaWiki.

The way Alias works is fundamentally wrong and only works because MediaWiki ignores the bad side effects that Alias introduces.

Proper rewrite rules just rewrite the path to /index.php, without any suffix or query modifications. Basically they just tell Apache, "For this url, run index.php without modifying anything". MediaWiki, not Apache, then reads the whole /wiki/Page path from the raw url in $_SERVER['REQUEST_URI'] and MediaWiki parses out the "Page" page name.

That is not how Alias works. A Alias /wiki /index.php alias actually tells apache to rewrite /wiki/Page to /index.php/Page and then passes "Page" to $_SERVER['PATH_INFO'] expecting you'll use PATH_INFO to get the "Page" title.

However, this is not actually a useful or good thing. Read the MediaWiki source code.

"PATH_INFO is mangled due to" "And also by Apache 2.x, double slashes are converted to single slashes."

If MediaWiki actually used the PATH_INFO that you get by using an Alias instead of a RewriteRule, your wiki's urls could be broken.

The only reason that Alias rewrites work, is because MediaWiki outright ignores the PATH_INFO and takes responsibility for parsing the "Page" title out of the url in REQUEST_URI. i.e. It basically throws the extra stuff Alias does into the trash and demotes it to a basic RewriteEngine rewrite.

DanShearer (talkcontribs)

Dantman - ack on the reasons for deprecating Alias, which themselves need to be mentioned when deprecating it and removing recipes.

Reply to "Added {{Outdated}} Template to flag major cleanup"

Why is the source code of this webpage so messy with translation tags?

2001:44C8:4512:B6D6:A16F:69E9:F0A3:8BD9 (talkcontribs)

Translation should be modular with translations of the main parts of this websites (excluding say "support desk" --- or not excluding it all) to other language websites as similar to how wikipedia enterprises are translated to different language "versions"; otherwise, a total "code spagetti" is caused;

Just to understand what this page is actually about I suggest this revised version of the opener chapter, without even one translation tag (also improving formatting and accessibility):

Wikipedia's short URLs.</translate>
For information on what Short URLs are or to get instructions on configuration for other servers see Manual:Short URL .

These instructions help setup Short URLs on Apache web server software.

The LiteSpeed webserver is Apache compatible and can be configured in relatively the same way.


Before starting, you need to decide on the name of your virtual "short url" pathTemplate:Calrification needed.

In this manual we'll recommend/assume the following but remember to use your own paths if they are different.

These following instructions have been included in an automated wizard (requires MediaWiki 1.17 or later) ---

  • If you just want your wiki configured quickly or you find the guide confusing then you may want to try that tool first.
  • If you do this, please note that you will need to edit or create a .htaccess file.
  • If you create it anew, please read on to further in this article about where to place the <tvar name=2>.htaccess file, and please note that this file will likely be in a different folder than the other file that will need to be edited (LocalSettings.php), which is in the installation folder.
  • if you have followed the MediaWiki recommendations). Please also note that using this wizard will not work on firewalled or private wikis, so in these cases, you can still try it out by making your wiki temporarily public by setting $wgGroupPermissions['*']['read'] to true ; remember to change it back to false once you are done.

Otherwise, follow the instructions below.

Server config

Find the right file

The recommended way to set up short URLs in Apache is by editing the Apache config files.

This requires that you have access to the server configuration.

If you are on a shared host, you most likely don't and will need to use a .htaccess file instead.

Using .htaccess files is less efficient and doesn't give you as much control when it comes to fancy setups with multiple domains but they are powerful enough to set up most short url configurations.

LiteSpeed users should use the .htaccess method.

Use the instructions in one of the following two sections, depending on whether you have root access or need to use .htaccess instead.
Reply to "Why is the source code of this webpage so messy with translation tags?"

Hello to the maintainers of this guide

2001:44C8:4405:657E:B5D6:B141:D388:F715 (talkcontribs)

I as a non native English speaker and as a person with a very fundamental and minor knowledge about Apache PCRE, find the guide very complex and unaccessible; passages are too long and I get the feeling of being overwhelmed with data.

I host my website on a shared server and maybe much of what's written here isn't relevant for me.

Please kindly consider to split this webpage into two --- one for people with IaaS and dedicated cloud-modeled hosting environments and one for people like me with Faas/PaaS cloud-modeled hosting environments.

Ciencia Al Poder (talkcontribs)
2001:44C8:4487:7025:E86D:73EB:DB08:F62F (talkcontribs)

@Ciencia Al Poder I am a professional developer and consultant in the fields I am in (which MediaWiki is not one of course); I think you should edit the link text to clarify that you explicitly mean to MediaWiki professional development and consulting ; that would be honorable and respected.

I actually want to do the change myself, without hiring anyone but I do think, with all respect to you, that your underestimate a didactance problem with that guide or at least unaware for such didactance problem (a problem in the context of accessing the data to general audience of readers and all types of webmasters; I for example was originally trained as a Drupal webmaster were, as I recall, shorts URLs are on by default (there was a time it just required a module to be installed before making it on by default). Without any desire to be annoying, I still think that the guide should at least wikitionally edited / textually-formatted and yesterday I meant to do this today myself later today and should do so.

Reply to "Hello to the maintainers of this guide"

Using Alias instead of RewriteEngine

Jcrummy (talkcontribs)

I was unable to get this working using RewriteEngine, however using Alias did. I added:

 Alias /wiki "/var/www/html/w/index.php/"

And everything works great. I did this in httpd.conf, which won't work if you don't have access to it.

Is there any reason why this wouldn't be a good idea?


Dantman (talkcontribs)

Alias basically turns /wiki/Foo into /w/index.php/Foo rather than just telling Apache to load index.php. I can't remember the specific things that ended up different but it isn't ideal.

In what way did it break when you tried configuring it with RewriteEngine? Was it a 404 or a 500 error? If it was a 500 error, what showed up in the error log?

Berot3 (talkcontribs)

If you google ''alias vs rewrite" you will find that apache recommends alias over rewrite. Mediawiki is special, butb I did not read of any problems with alias. Do you?

Also what do you mean by "just telling Apache to load index.php", to me it looks like alias and rewrite are both replacing one with the other, dont they?

Berot3 (talkcontribs)

So after some more testing I think it's worth mentioning in the Manual, that there is an alternative to rewrite with alias. In the Manual it only says that you can try using Alias if rewrite is not working in some cases. But I think this should be it's own part:

Note: this has to be done by altering the httpd.conf.

Simple instructions: httpd.conf source code:

Alias /w        ../apps/mediawiki/htdocs
Alias /wiki     ../apps/mediawiki/htdocs/index.php

LocalSettings.php source code

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

Can anyone confirm that this works?

Does anyone think that this has any downsides? (besides root-permissions for editing httpd.conf)

Berot3 (talkcontribs)

I think I forgot to mention something important. the apache-config is probably different when using virtual hosts. the code above is just for using with prefix and without vhost.

Reply to "Using Alias instead of RewriteEngine"