Jump to content

Manual talk:Short URL/Apache

Add topic
From mediawiki.org


$wgArticlePath

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


"However please note that there is no real valid reason to configure your wiki this way."

Except that as far as this unsophisticated user can tell, that appears to be the default configuration: http://www.mysite.com/wiki is the script path and articles are at http://mysite.com/wiki/index.php?title= . RiverStyx23 (talk) 00:39, 13 January 2013 (UTC)Reply

The phrasing is somewhat confusing, but it isn't wrong. What is important is that your virtual article path does not conflict with the script path. The default configuration has no separate article path, so there is no conflict.
# Default
Script path: /w
Article path: /w/index.php?title=$1
Now, if you decide to set up Short URLs, then you set up rewrite rules. In that case it is important that your shortcut does not match the script path:
# Short URLs: WRONG
Script path: /w
Article path: /w/$1
Here there is a conflict because /w/something can be an article or a file.
# Short URLs: RIGHT
Script path: /w
Article path: /wiki/$1
Here there is no conflict (this is also how Wikipedia.org and MediaWiki.org are configured). /w/something is a script, /wiki/something is an article. Krinkle (talk) 15:38, 18 January 2013 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

More straight explanations

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


I want to setup URLs as wiki.example.net/article but I don't understand at all what I need to do with .htaccess and LocalSettings.php Actiuinformatica (talk) 15:43, 20 March 2013 (UTC)Reply

If your wiki is public the guide here has been written into a tool at http://shorturls.redwerks.org/
I'm not sure how I can make the guide more understandable. Daniel Friesen (Dantman) (talk) 21:42, 20 March 2013 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

DOCUMENT_ROOT

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


In the description of the changes in httpd.conf, the following sequence of characters appear:

DOCUMENT_ROOT

Is it somehow related with variable $wg used in the LocalSetting.php? Should this sequence of characters be replaced to something specific for my computer or it should be copypasted as is?

As I understand, in order to provide the Short URL, the following lines should be added to httpd.conf

## http://www.mediawiki.org/wiki/Manual:Short_URL/Apache
# Enable the rewrite engine
RewriteEngine On

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

# Redirect / to Main Page
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]

Should I add these lines at the end of file httpd.conf ? Domitori (talk) 12:40, 12 April 2013 (UTC)Reply

P.S.: 'DOCUMENT_ROOT' is The document root directory under which the current script is executing, as defined in the server's configuration file. Domitori (talk) 12:40, 12 April 2013 (UTC)Reply

%{DOCUMENT_ROOT} is an Apache variable that automatically contains whatever the DocumentRoot is set to, leave it alone. It's not related to any of the LocalSettings.php config variables.
Where you put it will depend on whether you have root access and where the DocumentRoot, etc... for MediaWiki has been configured. Daniel Friesen (Dantman) (talk) 13:38, 12 April 2013 (UTC)Reply
Thanks, Daniel, for the quick answer. Perhaps, in my case, %{DOCUMENT_ROOT} has value /library/Server/Web/Data/Sites/Default ;
however, I cannot find the file, where this value is assigned.
Another problem: I found many directories called "apache2" at various places, and there are many files called httpd.conf there .
It is difficult to guess: which of them should be edited? Domitori (talk) 15:15, 12 April 2013 (UTC)Reply
%{DOCUMENT_ROOT} isn't assigned in any file. It's natively handled by Apache itself. You won't see where it's handled unless you go looking at Apache's pre-compiled C source code.
I can't really help you figure out what file you should use, different operating system distributions put it in different locations. You should probably ask whoever setup the server for you or perhaps just use .htaccess files instead. Daniel Friesen (Dantman) (talk) 22:47, 12 April 2013 (UTC)Reply
Thank you Daniel. The configuration of .htaccess does not look simpler, so, I still try to follow the suggestion
The recommended way to setup short URLs in Apache is by editing the Apache config files.
I think, I should edit httpd.conf ; it is first file mentioned in the instruction, that I find in my server.
Perhaps, I am not at the shared host, and, perhaps, I do not use a virtual host. (I am investigating the case.)
Also, I do not know, whether the restarting Apache is somehow related to the restarting of server or not.
I think, first, I should learn to restart the Apache. (Over-vice, if a crash, I shall not now, is it due to the error at the editing of httpd.conf or due to some error at the restarting procedure.) Domitori (talk) 05:40, 13 April 2013 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

AllowOverride All

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


I am a bit confused:

  1. I want to use /wiki/Page_title
  2. I have root access (on a cloud server running Ubuntu 13.04) and would prefer NOT to use an .htaccess file
  3. However when I put my domain name into shorturls.redwerks.org it will only generate the code for a .htaccess file.

Therefore, I ignore the auto-generated code and:

  1. go to edit the /etc/apache2/sites-available/default file.
  2. I am reminded Don't forget to enable overrides by AllowOverride All. It is disabled by default in Ubuntu 12.04 and Ubuntu 12.10. Nothing about Ubuntu 13:04. I assume this is referring to /etc/apache2/sites-available/default but AllowOverride All it appears several times there. Do I change them all or just one? I change them all, and save.
  3. I change the LocalSettings.php file as instructed
  4. Apache2 -k restart won´t work
  5. rebooting the server results in a correctly formed Short_url but the wiki itself is brokemn. Payo (talk) 23:21, 17 May 2013 (UTC)Reply
  • For the shorturl tool you can scroll down and open up the "Detected settings" section. Apache has a sub-section with an option called "I have root access on my server, plese output apache config." you can select that and submit to get Apache config rather than .htaccess config.
  • You can actually just use the same rules you put in .htaccess inside of your server config. The RewriteRules are the same. Alias based rules are not recommended anymore.
  • You shouldn't need the AllowOverride All. Daniel Friesen (Dantman) (talk) 05:30, 18 May 2013 (UTC)Reply
Thanks Daniel, that helps. I now have the Apache config code from the Redwerks code generator (which is brilliant for a novice like me):
RewriteEngine On
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/mediawiki/index.php [L]
RewriteRule ^/?$ %{DOCUMENT_ROOT}/mediawiki/index.php [L]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?mediawiki/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/mediawiki/thumb.php?f=$1&width=$2 [L,QSA,B]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?mediawiki/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/mediawiki/thumb.php?f=$1&width=$2&archived=1 [L,QSA,B]
...and I have the instruction: "Apache config: This configuration is meant to go the same block as whatever VirtualHost or other directive you have your wiki's DocumentRoot, ServerName, etc... already defined in." I presume this means I have to put the code into one of the blocks in etc/mediawiki/apache.conf which, in my case, looks like this:
# Uncomment this to add an alias.
# This does not work properly with virtual hosts..
Alias /mediawiki /var/lib/mediawiki
<Directory /var/lib/mediawiki/>
Options +FollowSymLinks
AllowOverride None
order allow,deny
allow from all
</Directory>
# some directories must be protected
<Directory /var/lib/mediawiki/config>
Options -FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/lib/mediawiki/upload>
Options -FollowSymLinks
AllowOverride None
</Directory>
So I paste in the Redwerks code into the first directory block (because I am not sure whatelse to do) and go to etc/mediawiki/LocalSettings.php and add the extra lines but I find that when I go back to my wiki I have correctly formed short urls http://www.mydomain.com/wiki/Main_Page but I now get a 404 Not Found page error.
Any suggestions? Payo (talk) 11:08, 18 May 2013 (UTC)Reply
Installing MediaWiki with an OS package like you have is generally a really bad idea. You are going to run into bugs and issues that you wouldn't usually run into. Like this one.
But anyways, the issues:
  • %{DOCUMENT_ROOT}/mediawiki doesn't exist since mediawiki is an alias for /var/lib/mediawiki/.
  • Don't put the RewriteRules inside that directory block. That directory block only applies to things in /mediawiki, so rules that apply to /wiki/ which is relative to the root won't be applied at all.
There are three things you can do:
OK: "Alias based rules are not recommended anymore." So I remove the Redwerks code from etc/mediawiki/apache.conf and add it to etc/apache2/sites-enabled/default.
When I restart apache:
...# apache2ctl restart
Syntax error on line 8 of /etc/apache2/sites-enabled/000-default:
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not
included in the server configuration
I guess that means I need to load the apache2 rewrite_module? :-( Payo (talk) 12:40, 18 May 2013 (UTC)Reply
sudo a2enmod rewrite fixed that. But no I am still getting the short url with a 404. Payo (talk) 12:55, 18 May 2013 (UTC)Reply
Could you show what config you're using now? Daniel Friesen (Dantman) (talk) 12:57, 18 May 2013 (UTC)Reply
Payo (talk) 14:17, 18 May 2013 (UTC)Reply
HI Daniel,
Here is what I have at /etc/apache2/sites-available/default:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
RewriteEngine On
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/mediawiki/index.php [L]
RewriteRule ^/?$ %{DOCUMENT_ROOT}/mediawiki/index.php [L]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?mediawiki/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+$
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?mediawiki/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)$
</Directory>
RewriteRule ^/?mediawiki/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)$
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
but maybe I should start again on a different version of ubuntu.
A little knowledge is a dangerous thing and, clearly, I am not really cut out for being a sysadmin. :-) Payo (talk) 14:30, 18 May 2013 (UTC)Reply
The VirtualHost is a better location, though you don't need it in the directory block.
But %{DOCUMENT_ROOT} is still being used. So the problem hasn't changed at all. Daniel Friesen (Dantman) (talk) 16:48, 18 May 2013 (UTC)Reply
Hi Daniel,
I did a manual re-install, followed your instructions to the letter and it is working fine now.
I have added a note to the instructions about enabling rewrite.load.
Thanks a lot!
Payo Payo (talk) 14:37, 18 May 2013 (UTC)Reply
- Payo (talk) 14:39, 18 May 2013 (UTC)Reply
- Payo (talk) 14:42, 18 May 2013 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Redirect long urls

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


How do I redirect queries like .../w/index.php?title=penguin to .../nationstates/penguin, like what Wikipedia does? I currently have RewriteRule ^/?nationstates(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L] in .htaccess and I use Apache. Thanks. Marianian (talk) 06:51, 28 September 2013 (UTC)Reply

Could you clarify your question a little. Are the short urls you setup to serve the [[penguin]] title at /nationstates/penguin working? Daniel Friesen (Dantman) (talk) 07:19, 28 September 2013 (UTC)Reply
Hello,
The short URLs (.../nationstates/Penguin) are working but so does (.../w/index.php?title=Penguin). When using the long version, the address bar doesn't change automatically to the short version (as Wikipedia does). Sorry about being new to this mod by I am trying to get all users to use the Short URL as it is cleaner. Marianian (talk) 01:10, 29 September 2013 (UTC)Reply
That's the intended behaviour of short URLs. If the /index.php url is perfect then no redirection is performed. Wikipedia doesn't redirect /w/index.php either.
See https://en.wikipedia.org/w/index.php?title=Penguin
The only time that redirection is performed is when the title param/article path text doesn't match the normalized form of the title and there is no additional query.
For example see https://en.wikipedia.org/wiki/penguin and https://en.wikipedia.org/w/index.php?title=penguin
The normalized form of "penguin" is "Penguin" so when the case doesn't match the proper one MW does a redirect. Coincidentally sending you from /index.php to /wiki because the redirection itself is done using the Title's url returning methods.
The exception to this as I mentioned is when there are extra query arguments. See how https://en.wikipedia.org/w/index.php?title=penguin&action=edit doesn't redirect even though it doesn't when the action=edit is missing. Daniel Friesen (Dantman) (talk) 02:37, 29 September 2013 (UTC)Reply
Thanks, I think that's something to clarify on the manual when one has spare time. Marianian (talk) 06:18, 29 September 2013 (UTC)Reply
I posted to the OP, but this isn't how it works anymore. Wikipedia actually redirects to short URL. MushToLearn (talk) 09:13, 30 August 2015 (UTC)Reply
So, 2 years later Wikipedia is actually redirecting to short URL's if you give it a long one (which includes the index.php part). I've been looking everywhere for how to set it up but to no avail. I think this is handled inside Mediawiki because it understands the difference between ...&action=view and ...&action=edit. MushToLearn (talk) 01:38, 29 August 2015 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Adding Favicon Caused Internal Server Error

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


I need some guidance on using short URL's with favicons? I've Google'd the problem a fair bit and tried the following with no success. I'm running Mediawiki on my own virtual server and am editing the /etc/apache2/sites-available/default file.

I've tried the following:

  • Adding RewriteCond %{REQUEST_URI} !^/favicon.ico before the index.php RewriteRule.
  • Adding RewriteRule .*\.ico$ – [L] before the index.php RewriteRule.

The wiki install is standard. Everything is at /etc/w/ with a symbolic link to /var/www. My apache default file is configured to follow symbolic links.

Here are the relevant lines in my LocalSettings.php file:

$wgScriptPath = "/w";

$wgArticlePath = "/wiki/$1"

$wgFavicon = "$wgScriptPath/favicon.ico"

If I comment out the favicon variable in the LocalSettings.php file the site runs flawlessly. If I leave the Favicon variable active I immediately get a 500 Internal Server Error.

EDIT: I looked in my Apache error.log and found the problem. Here's the error:

[Mon Mar 03 10:25:51 2014] [error] File does not exist: /var/www/favicon.ico

Now, why would apache be looking to /var/www/ for the favicon when I have set the location as $wgScriptPath/favicon.ico in LocalSettings.php? 199.27.232.62 17:21, 3 March 2014 (UTC)Reply

This is the OP. After scouring the log files I found that the error was due to not adding the semi-colon after:
$wgFavicon = "$wgScriptPath/favicon.ico" ;
Properly obeserving syntax saves so many headaches.  :) Seetheforest (talk) 21:26, 3 March 2014 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

"300 Multiple Choices"/ common basename error - what now?

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


My media wiki installation is located at /w on shared server with no root access. mod_rewrite is active, Apache 2.0 Handler. I have configured my .htaccess (located in /w/) file with the help of http://shorturls.redwerks.org so it reads like this

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

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?w/images/thumb/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/w/thumb.php?f=$1&width=$2 [L,QSA,B]

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?w/images/thumb/archive/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/w/thumb.php?f=$1&width=$2&archived=1 [L,QSA,B]

I have changed my LocalSettings.php to

$wgScriptPath = "/w";
$wgScriptExtension = ".php";
$wgArticlePath = "/wiki/$1";

It should be accessed via the domain http://spookyverse.de. The domain settings point to the /w directory. When I now access the wiki via the domain, the main pages works, although the link http://spookyverse.de/index.php?title=Hauptseite instead of http://spookyverse.de/wiki/Hauptseite, not sure if this another sign of my issue. However when I try to access any article from the main page or from previously bookmarked links (for example http://spookyverse.de/wiki/Drehorte) page I get the message

Multiple Choices

The document name you requested (/wiki/Drehorte) could not be found on this server. However, we found documents with names similar to the one you requested. Available documents:

/wiki.phtml/Drehorte (common basename)

I guess there is still something wrong with my .htaccess but as you can probably guess by using the redwerks tools I have no idea what exactly these rule (and I'm) are doing and why it won't work.

My hosting support told me to have the domain point to an extra folder with a .htaccess file (and only there) which contains

RewriteEngine On
RewriteRule ^(.*)$ http://spookyverse.de/$1 [L,R=301]

which will cause a loop/ too may redircets error.

I will be forever grateful for any help since unfortunately I do not understand the logics of regular expressions, I have tried for days now to fix this with manuals around the web, but no luck. CayceP (talk) 14:28, 26 June 2014 (UTC)Reply

I don't know where the "Multiple Choices" stuff is coming from.
But the .htaccess for your site should be in the root, not in /w, because it needs to rewrite things from /wiki/ which is not under /w, so it needs to be /.htaccess not /w/.htaccess. Daniel Friesen (Dantman) (talk) 07:23, 28 June 2014 (UTC)Reply
I know/suspected that but for some strange reason, the with .htaccess in root the wiki was/s not working correctly (error 404 or the common basename and internal errors although the settings seem correct). The one in /w (or /wiki) worked.
Of course I deactivated the .htaccess in /w/ and /wiki/ while trying around).
Initially I accidentally installed the wiki in /wiki not /w which used to work so far (only the skins weren't working) but now by trying around and changing back and forth with those friggin .htaccess now some images are not longer displayed and the skins are not working even when I restore the original working .htaccess *argg*.
so with wiki installation in /w/ active (and the initial wiki in /wiki/ deactivated) and .htaccess in root (the wikis Main pages seem to work, but upon calling articles, the common base name error appears)
RewriteEngine On
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]
this one causes the common base name error on the main page
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/w/index.php [L]
CayceP (talk) 09:51, 30 June 2014 (UTC)Reply
I'm not sure what you're saying is and isn't working currently. Daniel Friesen (Dantman) (talk) 10:03, 30 June 2014 (UTC)Reply
I have this entry in the .htaccess in root (wiki installed to w/):
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]
Which is obviously not working.
The only page that is displayed for me is http://spookyverse.de/index.php?title=Hauptseite.
But trying to open any other link from there like http://spookyverse.de/wiki/Drehorte produced a common basename error. CayceP (talk) 10:23, 30 June 2014 (UTC)Reply
Firstly, it looks like that Drehorte page is loading.
And it looks like you have a completely messed up configuration and structure.
You're insisting to me that your wiki is installed in /w/index.php
However /w/api.php doesn't work, but /api.php does so you have MW in the root, not in /w it seems.
And you have scriptpath configured as /wiki/. Daniel Friesen (Dantman) (talk) 11:07, 30 June 2014 (UTC)Reply
Oh, I'm so sorry. I was trying to re-established the status quo (the wiki that was working but the skins which has been installed in the wrong directory [/wiki]). It's now switched it back to problematic installation and I won't touch it for the time being. (w/.api.php) is now working).
ETA: I noticed that some links seem to work for example the page history link is rendered as http://spookyverse.de/w/index.php?title=Hauptseite&action=history (works) while the articles do not (since they called via the http://spookyverse.de/wiki/Pagename link). Links called via http://spookyverse.de/index.php/Charaktere do work also. CayceP (talk) 11:37, 30 June 2014 (UTC)Reply
Sorry, I had to reverse to the working installation located in /wiki/ for the time being so the site is at least usable. Thanks for trying to help, though. CayceP (talk) 14:13, 2 July 2014 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

shorturls.redwerks.org NOT WORKS

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


The http://shorturls.redwerks.org not works with example.com as "root web folder", even http://example.com/wiki_folder produces "Sorry, this does not look like a wiki"! 189.62.89.175 09:37, 8 August 2014 (UTC)Reply

That's because http://example.com/ is not a MediaWiki installation, and neither is http://example.com/wiki_folder.
The tool is supposed to be given the URL to a real MediaWiki installation. Daniel Friesen (Dantman) (talk) 19:11, 8 August 2014 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

shorturls.redwerks.org errors

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


  • MediaWiki 1.23
  • Apache 2.4.9
  • MySQL 5.6.17
  • PHP 5.5.12

To duplicate:

  1. Go to http://shorturls.redwerks.org/
  2. Enter this URL: http://www.gregariousjb.com/mediawiki/index.php/Main_Page
    • Error: Encountered invalid XML while trying to find the API
  3. Enter this URL: http://www.gregariousjb.com/mediawiki/index.php/
    • Error: Sorry, this does not look like a wiki.
  4. Enter this URL: http://www.gregariousjb.com/mediawiki/
    • (Massive 403 "Forbidden" error that fills the screen)

If it helps, I'm hosting it on my own computer using WAMP, and a DNS host record via Namecheap.com. However, using only my IP gives me the same error.

On a side note, the http://shorturls.redwerks.org/ website can easily be made more informative. An example URL near the form would tell us how the URL might look and what we need to include. Also, you're playing with fire when you write three large paragraphs of text instead of short, concise instructions in a numbered list. The same can be said of the Manual:Short_URL/Apache page. It's really long and confusing. GregariousJB (talk) 21:34, 15 September 2014 (UTC)Reply

Your site isn't available at the moment so I can't debug the errors.
The first error typically happens when your site outputs PHP errors/notices due to something broken in an extension or your settings file.
I've added a placeholder to the url input in the dev version, I'll look into improving the page tomorrow, then deploy it. Daniel Friesen (Dantman) (talk) 04:59, 18 September 2014 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Multiple MW installations on one Apache

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


I have multiple MW installations on a single Apache Webserver. The steps given here mention the short URLs considering that there is only one MW installation per Webserver.

Anyone got an idea as to what to do do to make multiple clean URLs on multiple installations but on same Webserver.

eg: http://<generic URL>/<specific installation 1>/Page_name_X http://<generic URL>/<specific installation 2>/Page_name_Y

For security and company policy reasons cannot share the exact installations or paths as it is not live yet on Internet.


MW: 1.18.2 Apache HTTPD: 2.4 PHP: 5.3.5 Postgres: 9.2 Pdr3112 (talk) 08:37, 18 September 2014 (UTC)Reply

Configure your wiki one at a time, the technique you use will vary depending on how the directories intersect.
If your multiple wiki are setup like this:
You won't need to do anything special at all. .htaccess files only need to be high enough up in the path that they are above both the /index.php and /wiki/ paths. So you'll have /departmentA/.htaccess and /departmentB/.htaccess and wont need to do anything.
If your multiple wiki aresetp like this:
Then the wiki will share a common root since for a .htaccess to apply to both /departmentA_wiki and /departmentA it would need to be in the root .htaccess. But it won't be too hard, the rules that setup your short urls don't intersect so all you'll do is put the config you get for both wiki into the same /.htaccess file.
The only tweaks you'll want to make to what you get are that you'll only need one RewriteEngine On and you might want to remove the RewriteRule ^/?$ %{DOCUMENT_ROOT}/w/index.php [L] line that redirects the site root to the wiki's mainpage. Daniel Friesen (Dantman) (talk) 21:33, 18 September 2014 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

What does it mean when it says: "The MediaWiki directory is located at: /w" ?

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


I have a question on the very first requirement in this guide.

Quote: "The MediaWiki directory is located at: /w"

What does this mean?

  1. The mediawiki tar has been extracted in to /var/lib/mediawiki, and then a symlink named "w" has been created in /var/www/html/ to point to /var/lib/mediawiki ?
  2. The mediawiki tar has been extracted in to /w . I.e. a directory called /w on the root of the server filesystem ?
  3. There is no physical "w" directory on in the filesystem. There is an alias in one of the Apache config files (which one and in what section?) of the form: "Alias /w /var/lib/mediawiki"
  4. Or something else?

Can this be clarified please, perhaps with an example of every place where /w is referenced so that any attempt to change it will get all of the occurrences? Thanks. Gareth.randall (talk) 08:34, 10 December 2014 (UTC)Reply

Something else: It means the tarball has been extracted into the folder /w. Later down the page we expect that this folder is located directly inside the webroot. E.g. if your webroot is /var/www, then /w would have to be /var/www/w/. 88.130.88.189 22:58, 18 December 2014 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Using Alias instead of RewriteEngine

[edit]
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?
-John Jcrummy (talk) 21:56, 28 December 2014 (UTC)Reply
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? Daniel Friesen (Dantman) (talk) 03:01, 29 December 2014 (UTC)Reply
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 (talk) 16:43, 26 January 2021 (UTC)Reply
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 (talk) 12:51, 11 May 2021 (UTC)Reply
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. Berot3 (talk) 17:40, 11 May 2021 (UTC)Reply

Never applies the rules even when AllowOverride is on.

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


Centos 7, Apache 2.4.6

So, I am trying to short URL like this:

http://mywiki.com/index.php/article</pre>
to
<pre>http://mywiki.com/wiki/article</pre>

[Edit: I changed this from mywiki.com/article to mywiki.com/wiki/article.  Sorry, I originally wrote this after doing command line for about 8 hours straight.]

I have mod_rewrite enabled:

<pre>grep -i LoadModule /etc/httpd/conf/httpd.conf | grep rewrite</pre>
gives
<pre>LoadModule rewrite_module modules/mod_rewrite.so</pre>

I have a symbolic link called "fts" that points to the root folder of the wiki documents.

I go to my root folder of my wiki documents:

<pre>cd /var/www/html/mediawiki-1.24.1 
sudo vim .htaccess</pre>

and then I create this .htaccess file

<pre>## http://www.mediawiki.org/wiki/Manual:Short_URL/Apache
 
# Enable the rewrite engine
RewriteEngine On
 
# Short url for wiki pages
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/fts/index.php [L]
 
# Redirect / to Main Page
RewriteRule ^/*$ %{DOCUMENT_ROOT}/fts/index.php [L]</pre>

Then I load up my wiki and nothing is different.  So, I go back to to httpd.conf and make sure AllowOverrides All is on:

<pre>grep -i AllowOverride /etc/httpd/conf/httpd.conf</pre>
gives
<pre>AllowOverride None
AllowOverride All <--- this is the <Directory "/var/www/html"> section one
AllowOverride None
AllowOverride None</pre>

What's up here?  I can't figure out why nothing is going on.  I'm restarting httpd every time I do an edit to anything. Nathan in Oregon 23:24, 1 February 2015 (UTC)
:Note that ''only'' adding stuff to apache config files doesn't automagically make MediaWiki aware of the new URL scheme. You should change $wgArticlePath accordingly so MediaWiki generates URLs following that scheme.
:You said you want your URLS to be http://mywiki.com/article, but you set up rules for URLs like http://mywiki.com/wiki/article:
:<code> RewriteRule ^/?'''wiki'''(/.*)?$ %{DOCUMENT_ROOT}/fts/index.php [L]</code>
:Also note that the URL scheme you propose is not recommended, since there are more paths under your mywiki.com domain that shouldn't be treated as wiki pages. Looks like you're missing reading/understanding some important parts of the manual.
:And I don't understand why do you have a fts link pointing to the parent folder. That's really awkward. [[User:Ciencia Al Poder|Ciencia Al Poder]] ([[User talk:Ciencia Al Poder|talk]]) 20:46, 2 February 2015 (UTC)
::test [[Special:Contributions/67.171.179.59|67.171.179.59]] 04:08, 4 February 2015 (UTC)
{{Archive bottom}}

== Cann't get this extension working ==
{{Archive top|result=probably not relevant anymore|status=resolved}}

Hi,

I am not able to get this extension working. All my efforts either ends up in 400 not found or Bad Request.

what I am doing is, added following in my LocalSettings.php

<syntaxhighlight lang="php" strict="">
require_once("$IP/extensions/ShortLinks/ShortLinks.php");
$wgArticlePath = "wiki/$1";
$wgUsePathInfo = false;
</syntaxhighlight>


Added following in httpd.conf file:

<syntaxhighlight lang="php" strict="">
LoadModule rewrite_module modules/mod_rewrite.so

<syntaxhighlight lang="php" strict>
<VirtualHost IP:port no>
RewriteEngine On
DocumentRoot "/path/to/apache/webroot/"

<Directory /path/to/apache/webroot/>
AllowOverride All
Require all granted
</Directory>

RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/Mediawiki-1.23/index.php [L]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
	
</VirtualHost>
</syntaxhighlight>

Value for following variables are:
<syntaxhighlight lang="php" strict="">
$wgArticlePath = "/wiki/$1";
$wgScriptPath = "/Mediawiki-1.23";
</syntaxhighlight>

What I am expecting is, that in the browser I should get the URL as "http://IP/Mediawiki-1.23/ " (w/o the index.php) and also it should be able to navigate within the wiki w/o having the index.php in the URL.
I am trying this on Apache 2.4 and PHP 5.4. Please suggest, how can I get this working? [[User:Solanki|Solanki]] ([[User talk:Solanki|talk]]) 10:42, 3 February 2015 (UTC)
:<code>$wgArticlePath = "wiki/$1";</code> is wrong, it must start with /.
:Besides that it doesn't look like you have followed the guide at all.
:The -f and -d don't apply when doing /wiki/$1 urls and mediawiki is in a separate folder and they're in the wrong spot.
:And there is no mention anywhere of <code>RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]</code>, which is likely intercepting any url belonging to your wiki and sending it somewhere else. [[User:Dantman|Daniel Friesen (Dantman)]] ([[User talk:Dantman|talk]]) 10:49, 3 February 2015 (UTC)
::Actually, when I wasn't able to make it work, I took reference from many sources and clubbed too many parameters in the hope that it would work.
::Apparently, now it works, Thanks to you.
::The only thing I am wondering now, is how to get it working for every links within the wiki like the way it is working for main page. [[User:Solanki|Solanki]] ([[User talk:Solanki|talk]]) 14:58, 3 February 2015 (UTC)
:::If it doesn't work outside the main page, are you sure $wgArticlePath is set right? [[User:Dantman|Daniel Friesen (Dantman)]] ([[User talk:Dantman|talk]]) 12:34, 4 February 2015 (UTC)
::::I have set: $wgArticlePath = "/wiki/$1";
::::What I am trying to say is, if u crate a new page, then the URL for that page must behave in the same manner, but here it isn't.
::::So, Is there any thing else I need to take care of? [[User:Solanki|Solanki]] ([[User talk:Solanki|talk]]) 07:19, 5 February 2015 (UTC)
{{Archive bottom}}

== Some pages have links (on buttons) that do not obey this setup ==
{{Archive top|result="MediaWiki's short urls only apply to simple page views."|status=resolved}}

I achieved what was promised - short URL's, for most pages.

However, there are pages that generate URL's to other pages that do not respect this setup.

For example, after setting it all up, I tried to uplaod a sample picture and then delete it.

"Delete" link on that page is generated to use NOT pretty version of the url, ie: 
/w/index.php?action-delete&...

Same for many other links that are action "buttons":
Go button on running queires on secial pages, 
link to view current user account - all have non-magled, un-pretty url in them;

My guess, php code behind those pages does not use $wgArticlePath variable, but instead uses raw $wgScriptPath, which causes them to generate links against this setup;

Also, upload page actions do not fall under posted rewrite rules. uploaded images were not always showing up.
Had to add another rule to rewrite prefix of urls generated with $wgUploadDirectory [[Special:Contributions/68.174.167.16|68.174.167.16]] 01:20, 22 June 2015 (UTC)
:MediaWiki's short urls only apply to simple page views. Most URLs with queries in them point to index.php so that they can be included in <code>robots.txt</code>. Some &action= urls can be made to use a different short url if you configure $wgActionPaths for them. [[User:Dantman|Daniel Friesen (Dantman)]] ([[User talk:Dantman|talk]]) 02:30, 22 June 2015 (UTC)
{{Archive bottom}}

== .htaccess: Rewriting /$IP to a subdomain ==
{{Archive top|result=done|status=resolved}}

I am on a shared Apache host. Relative to my folder's root, MediaWiki is installed at /connections. I would like to rewrite it to connections.mydomain.com. I couldn't find any way to set up this URL scheme in the MediaWiki ShortURL Builder at Redwerks, so I set up the subdomain through my web host. I then tried the tool again, which gave me the following:
<syntaxhighlight lang="php" strict="">
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/index.php [L]

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&width=$2 [L,QSA,B]

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&width=$2&archived=1 [L,QSA,B]
</syntaxhighlight>
<syntaxhighlight lang="php" strict="">
$wgScriptPath = "";
$wgScriptExtension = ".php";
$wgArticlePath = "/$1";
$wgUsePathInfo = true;
$wgEnableUploads  = true;
$wgGenerateThumbnailOnParse = false;
</syntaxhighlight>
I put these in an .htaccess file at /connections, but then got 500 errors. What am I doing wrong? [[User:Jkmartindale|James Martindale]] ([[User talk:Jkmartindale|talk]]) 05:15, 22 February 2016 (UTC)
:I don't see any obvious syntax error so this may be a misconfiguration on the server that doesn't allow defining rewrite rules on .htaccess. [http://stackoverflow.com/a/15850426 See this SO answer] for example.
:You may have an error log for your subdomain to look a detailed error message. [[User:Ciencia Al Poder|Ciencia Al Poder]] ([[User talk:Ciencia Al Poder|talk]]) 13:05, 22 February 2016 (UTC)
:I currently use RewriteEngine to force www.domain.com to domain.com, so I think I it works within .htaccess and it may just be the way my host configures the subdomain. Is there a way to catch the subdomain at domain.com and rewrite it to /connections without using my web host?
:I'll ask my host for the error log. [[User:Jkmartindale|James Martindale]] ([[User talk:Jkmartindale|talk]]) 14:59, 22 February 2016 (UTC)
{{Archive bottom}}

== Short URLs not working ==
{{Archive top|result=seems resolved|status=resolved}}

I went to shorturls.redwerks.org and typed the URL of wkse. '''Encountered invalid XML while trying to find the API''' shows up so I try to do it myself.

I followed the manual and this is not working:
<pre>RewriteEngine On
RewriteBase /wkse
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/index.php [L]
$wgScriptPath       = "";
$wgScriptExtension  = ".php";
$wgArticlePath      = "/$1";

It redirects to error404.000webhost.com. Luis/stranger195 (talkcontribsguestbook) 01:50, 23 March 2016 (UTC)Reply

Without knowing what's your expected URL structure, it's hard to tell where's the error, since we can't know where in the document root your wiki resides, how your short URLs should look, etc
From what you post I see a discrepancy: You have RewriteBase /wkse, so I assume your short URL should look like yourdomain.com/wkse/Pagename, but you have $wgArticlePath = "/$1"; which will be interpreted as yourdomain.com/Pagename Ciencia Al Poder (talk) 10:21, 23 March 2016 (UTC)Reply
Right, I forgot about that.
The index.php, LocalSettings.php, and other files reside in the root folder. The expected short URL is http://wkse.luisantonimperial.net23.net/wkse:Main_Page.
The RewriteBase is needed because 000webhost doesn't use actual sub(sub)domains, the contents of wkse.luisantonimperial.net23.net reside in luisantonimperial.net23.net/wkse.
What I want is:
The URL structure you propose will be problematic, as already warned on this page.
Besides that, your server doesn't seem to be properly configured, or you don't seem to have an index.php file on the document root of the server, since accessing it gives a straight 404 error page. Ciencia Al Poder (talk) 20:50, 23 March 2016 (UTC)Reply
accessing it gives a straight 404 error page.
That's because I didn't remove the problematic .htaccess code before you accessed it. I removed it now. Luis/stranger195 (talkcontribsguestbook) 08:32, 27 March 2016 (UTC)Reply
That may indicate your hosting doesn't support URL rewriting, since those rewrite rules doesn't match /wkse and shouldn't have any effect. Apache just errors out if it finds configuration settings that doesn't understand in .htaccess Ciencia Al Poder (talk) 11:27, 27 March 2016 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Complete redirect

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


Noticed that mediawiki.org and wikipedia.org have complete redirect: https://www.mediawiki.org/w/index.php?title=Article goes directly to https://www.mediawiki.org/wiki/Article

On a normal wiki with rewrite rules that doesn't happen.

Any help would be greatly appreciated 86.126.188.13 (talk) 23:58, 7 September 2016 (UTC)Reply

It works for me since MediaWiki 1.26. I don't see this behavior in MediaWiki 1.25. Check if your MediaWiki is 1.26 or greater. Ciencia Al Poder (talk) 12:16, 8 September 2016 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Need some help with redirects in .htaccess

[edit]

didn't reply

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: http://mydomain.com/wiki/Articlename redirects to https://mydomain.com/wiki/Main_Page, but I want to redirect to https://mydomain.com/wiki/Articlename

Example 2: https://www.mydomain.com/wiki/Articlename redirects to https://mydomain.com/wiki/Main_Page, but I want to redirect to https://mydomain.com/wiki/Articlename

This is my settings in .htaccess:

<IfModule rewrite_module>
RewriteEngine On
Options +FollowSymlinks

# Redirect Mydomain.com 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 (.*) http://mydomain.com/$1 [L,R=301]

# Permanent redirect HTTP to HTTPS
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mydomain.com/$1 [R=301,L]
</IfModule>

Any idea what I'm doing wrong?

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

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)Reply
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' Stevio Bee (talk) 06:09, 5 March 2022 (UTC)Reply

What does this mean?

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


This makes absolutely no sense:

"Note: If you are using a script path and article path that match such as /mywiki/index.php and /mywiki/Article you will also need to use the same two RewriteCond lines on your RewriteRule. However please note that there is no real valid reason to configure your wiki this way. If your article path is already a subdirectory you should just move your wiki's script path to another directory. Such as /w/index.php and /mywiki/Article or /my/index.php and /mywiki/Article."

What does *any* of it mean? What is it talking about? What should be moved where, and what's supposed to be matching? Teekin (talk) 20:09, 2 August 2017 (UTC)Reply

I agree, not a easy subject. I'll try my best. With other words:
if you the folder where the actual index.php is (under htdocs for example) AND you want the subdirectory(/mywiki)-path to be the same (like http://domain.tld/mywiki), than you need additonal RewriteRules.
But as it states next "However please note that there is no real valid reason to configure your wiki this way", you shouldnt really do it like that. It is simply not recommendet and also there are no RewriteRules that I know of that could solve this.
In the next sentence after that, it tells what the recommended way is: name the folder "w" where the actual mediawiki is stored and that's it! Berot3 (talk) 16:23, 26 January 2021 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Subdomain broken DNS

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


Dog1994 (talk) 01:35, 4 December 2017 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Don't redirect from root

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


I've used the Redwerks tool to create the short url to "/wiki/$1", with the wiki being stored in "/public_html/mediawiki/w" (shared host). However, I still want to use the standard URL to reach a normal site and only "www.[domain].com/wiki" to lead to the wiki. But since the .htaccess file for this configuration has to be placed in /public_html/, it always redirects. What will have to be changed? 145.44.77.224 (talk) 09:32, 24 May 2018 (UTC)Reply

Is the domain specified in $wgServer in yourLocalSettings.php ? If so: For my wiki (also on a shared host) it only works correct if I put the .htaccesss in the w/ folder (which one shouldn't do according to this website but yet it works). Maybe give that a try? CayceP (talk) 11:06, 24 May 2018 (UTC)Reply
Unfortunately, that doesn't work, regardless of where I place the file or what the settings are in LocalSettings. Yes, the domain is specified. 145.44.77.224 (talk) 11:39, 24 May 2018 (UTC)Reply
That is odd. Does it change anything if you temporarily rename the .htaccess to no.htaccess and put your domain name in $wgServer? This should have an effect (either that you get a 500 error or it you get an ambiguous name message etc), if not than there is probably some other config file or .htaccess on work and your .htaccess has no effect what so ever at the moment. CayceP (talk) 11:55, 24 May 2018 (UTC)Reply
If I do anything other than what I have (e.g. move .htaccess anywhere other then /public_html/, change the ScriptPath, etc.) I get a 404 error.
LocalSettings.php
$wgScriptPath = "/mediawiki/w";
$wgScriptExtension = ".php";
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;
$wgServer = "https://[domain].com";
.htaccess (in /public_html/)
RewriteEngine On
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/mediawiki/w/index.php [L]
RewriteRule ^/?$ %{DOCUMENT_ROOT}/mediawiki/w/index.php [L]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?mediawiki/w/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/mediawiki/w/thumb.php?f=$1&width=$2 [L,QSA,B]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?mediawiki/w/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/mediawiki/w/thumb.php?f=$1&width=$2&archived=1 [L,QSA,B]
145.44.77.224 (talk) 12:06, 24 May 2018 (UTC)Reply
This line is what makes the automatic redirect from root:
RewriteRule ^/?$ %{DOCUMENT_ROOT}/mediawiki/w/index.php [L]
Remove it and it should work. Ciencia Al Poder (talk) 09:31, 25 May 2018 (UTC)Reply
Thank you, it works now. I should have known this myself. I don't know why I missed that line. 145.44.77.224 (talk) 10:15, 25 May 2018 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

ShortURL constantly returns 404 Not Found

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


CentOS7

MediaWiki 1.30.0

PHP 7.1.16 (apache2handler)

MariaDB 5.5.56-MariaDB

ICU 50.1.2

I have a mediawiki running on a directory, /mw/ and it generates the /mw/index.php/Article

I just want to remove the index.php section.

I have root access and have run Redworks' ShortURL tool. My ShortURL stuff to go into my virtual host is as follows:

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d

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

And my LocalSettings.php

$wgScriptPath = "/mw";

$wgScriptExtension = ".php";

$wgArticlePath = "{$wgScriptPath}/$1";

It seems to work, but I constantly get a 404 Not Found error. It redirects but doesn't actually process.

I cannot get it to work no matter what. Any help would be appreciated. 98.21.171.79 (talk) 23:40, 15 September 2018 (UTC)Reply

If your index.php path is at /mw/index.php, you should't make your URLs look like /mw/$1, because this is a source of conflicts.
Please choose a different scheme, for example, articles in /wiki/$1 Ciencia Al Poder (talk) 16:14, 16 September 2018 (UTC)Reply
I did. Even using /wiki/$1 I get a 404 Not Found error. Below is my info:
RewriteEngine On
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/mw/index.php [L]
RewriteRule ^/?$ %{DOCUMENT_ROOT}/mw/index.php [L]
$wgScriptPath = "/mw";
$wgScriptExtension = ".php";
$wgArticlePath = "/wiki/$1";
It writes to /wiki/ fine but I still get a 404 error. 98.21.171.79 (talk) 19:00, 16 September 2018 (UTC)Reply
The configuration looks good.
If you access the "/mw/index.php" path from your browser, does it display the main page? Ciencia Al Poder (talk) 21:18, 16 September 2018 (UTC)Reply
If I put index.php/Main_Page, yes.
If I put index.php/ it redirects around as /wiki/ 98.21.171.79 (talk) 22:17, 16 September 2018 (UTC)Reply
Be sure there's no folder named "wiki" on the webserver Ciencia Al Poder (talk) 10:06, 17 September 2018 (UTC)Reply
There isn't.

98.21.171.79 (talk) 01:43, 22 February 2019 (UTC)Reply
I think your rewrite rules are not being taken into account by the webserver. Maybe server admin disabled the ability to override/create rewrite rules. Ciencia Al Poder (talk) 10:18, 22 February 2019 (UTC)Reply
Провозился 2 дня. Всё делал как в инструкциях... Переустанавливал вики, специально в подкаталог "w". Всё время выдавало 404, при этом путь менялся как нужно //сайт/wiki/Page_title
Настраивал через .htaccess . В итоге просто нужно .htaccess поместить рядом с папкой "w". До этого был на каталог выше. После всё заработало. 81.163.151.85 (talk) 08:19, 19 April 2019 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

%{DOCUMENT_ROOT} on windows creates 403 error

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


On local Windows 10 apache installation %{DOCUMENT_ROOT} on windows creates 403 error.

## http://www.mediawiki.org/wiki/Manual:Short_URL/Apache

# Enable the rewrite engine

RewriteEngine On

# Short URL for wiki pages

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

# Redirect / to Main Page

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

You don't have permission to access /G:/WebSites/pw/w/index.php on this server.

[Sun Nov 18 10:55:39.710853 2018]

[core:error]

[pid 11584:tid 1264] (20023)

The given path was above the root path:

[client 127.0.0.1:20427] AH00127: Cannot map GET / HTTP/1.1 to file

This configuration however works fine:

## http://www.mediawiki.org/wiki/Manual:Short_URL/Apache

# Enable the rewrite engine

RewriteEngine On

# Short URL for wiki pages

RewriteRule ^/?wiki(/.*)?$ /w/index.php [L]

# Redirect / to Main Page

RewriteRule ^/*$ /w/index.php [L] 109.169.141.36 (talk) 07:10, 18 November 2018 (UTC)Reply

I'm also on windows and didnt have any issues. But Maybe you want to use alias instead, if you still have this problem. Berot3 (talk) 16:01, 26 January 2021 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Ubuntu: Forward www.mywiki.com to http://www.mywiki.com/w/index.php/Main_Page

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


Change directory to /etc/apache2, edit apache2.conf and under the /var/www change AllowOverride from None to: All

Find the root directory of your webserver, /var/www/html, create a file there called .htaccess and add this:

RedirectMatch ^/$ /w/

Now restart your service: sudo service apache2 restart 65.35.141.170 (talk) 18:25, 4 January 2019 (UTC)Reply

The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.
[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


Followed the instructions for apache - wound up with a mess of formatting and no images.


If this helps others - had to do the following to get it to work:

In the apache2.conf file:

## don't rewrite load.php, api.php, and other php scripts.  this got the sidebar and CSS/formatting to work
RewriteRule ^/?wiki.*\.php - [L]

## don't rewrite images/icons in the resources folder.  this got icons to work
RewriteRule ^/?wiki/resources - [L]

## rewrite to short url
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/wiki/index.php [L,QSA]

I suspect I'll need to do a "not images" type of rule also, but haven't uploaded any images to this wiki yet. Sojourner9 (talk) 16:54, 22 March 2019 (UTC)Reply

The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Not working on Ubuntu

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


I've followed the Apache instructions to the letter, and just get a 404 error. Straight up doesn't work, and I can't figure out why. Tried putting the rules in 000-default.conf, and mediawiki.conf, and apache2.conf (one at a time), and still nothing. AllowOverride is set to All as well.

Running Ubuntu 18, any thoughts? Brickscrap (talk) 16:16, 16 April 2019 (UTC)Reply

Ok so my Wiki is on port 8081 and the VirtualHost was set to 80, so it kind of works now, but when I visit the page it's completely broken, all formatting etc... Have tried everything I can think of, including what's posted below, but nothing... Brickscrap (talk) 17:17, 16 April 2019 (UTC)Reply
Hit F12, open the network tab and reload the page. Look at any error in requests (like HTTP status 404, 400, 500...), and figure out if the URL it's trying to request makes sense. If it makes sense, problem is in apache config. If not, problem is in MediaWiki config. Ciencia Al Poder (talk) 19:13, 16 April 2019 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Horribly confused

[edit]

I've read this, and a wide range of other pages I've found in searches, and still have no clue how to get this ShortURL malarky working. Can somebody help me out? I've installed on localhost, so have root access. But when I try to write these rules and try to restart Apache, I'm met with an error message like below:


AH00526: Syntax error on line 14 of /etc/apache2/sites-enabled/000-default.conf:

Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration


Where and exactly how am I suppose to set up this stuff?? Am I supposed to put these lines of RewriteEngine and such inside some type of tags??


Hopefully I'm fiddling with the right file at least, but this is the entirety of it.


<VirtualHost *:80>

   # The ServerName directive sets the request scheme, hostname and port that

   # the server uses to identify itself. This is used when creating

   # redirection URLs. In the context of virtual hosts, the ServerName

   # specifies what hostname must appear in the request's Host: header to

   # match this virtual host. For the default virtual host (this file) this

   # value is not decisive as it is used as a last resort host regardless.

   # However, you must set it for any further virtual host explicitly.

   #ServerName www.example.com

   ServerAdmin webmaster@localhost

   DocumentRoot /var/www/html

   # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,

   # error, crit, alert, emerg.

   # It is also possible to configure the loglevel for particular

   # modules, e.g.

   #LogLevel info ssl:warn

   ErrorLog ${APACHE_LOG_DIR}/error.log

   CustomLog ${APACHE_LOG_DIR}/access.log combined

   # For most configuration files from conf-available/, which are

   # enabled or disabled at a global level, it is possible to

   # include a line for only one particular virtual host. For example the

   # following line enables the CGI configuration for this host only

   # after it has been globally disabled with "a2disconf".

   #Include conf-available/serve-cgi-bin.conf

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet Pangaearocks (talk) 17:36, 22 July 2019 (UTC)Reply

Apparently, you need to install or enable mod_rewrite first, to be able to use that syntax in the apache configuration. That may largely depend on the linux distribution you use. There's an example: https://stackoverflow.com/questions/869092/how-to-enable-mod-rewrite-for-apache-2-2 Ciencia Al Poder (talk) 20:37, 22 July 2019 (UTC)Reply
Thank you, that got me a little further. The wiki loads, but the main page looks weird, with the sidebar on the very bottom, and with seemingly no css. If I try http://localhost/wiki/Main_Page, however, there is a Not found error message.
Is there an example somewhere of what these files are supposed to look like when completed and working?
Right now my sites-available .conf holds (with the comments sections removed):
<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html
RewriteEngine On
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/index.php [L]
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
While the LocalSettings.php file has:
## The URL base path to the directory containing the wiki;
## defaults for all runtime URL paths are based off of this.
## For more information on customizing the URLs
## (like /w/index.php/Page_title to /wiki/Page_title) please see:
## https://www.mediawiki.org/wiki/Manual:Short_URL
$wgScriptPath = "";
$wgScriptExtension = ".php";
$wgArticlePath = "/wiki/$1";
## The protocol and server name to use in fully-qualified URLs
$wgServer = "http://localhost";
## The URL path to static resources (images, scripts, etc.)
$wgResourceBasePath = $wgScriptPath;
Some of that was gotten to by using https://shorturls.redwerks.org. Perhaps it is completely messed up, but it's hard to understand what is supposed to be written in the files. Pangaearocks (talk) 22:12, 22 July 2019 (UTC)Reply
do you still have this problem? I had some hard time getting it to work for myself, maybe I can help. Berot3 (talk) 16:04, 26 January 2021 (UTC)Reply

Lighttpd

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


Is there a way to do this, using lighttpd mod_rewrite? --Tinker Bell 20:27, 17 August 2019 (UTC)Reply

The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

What about colons issue on Windows for Special Pages?

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


This Short URL/Apache is great, no doubt, but very confusing instructions and not covering the Windows specific issues with colons.

Adding a warning on Manual:Short URL/Page title -- Windows & Apache without 403 on Special Pages is great too for redirecting here,

but this is the one that saved my life in minutes.


Mirrabeau (talk) 11:03, 8 February 2020 (UTC)Reply

The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Thanks for the MediaWiki ShortURL Builder

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


I'm not sure whether this discussion is just to flag problems, but I wanted to shout a big THANKS to whoever put together the MediaWiki ShortURL Builder. I'm a new MediaWiki user, and not a programmer, so I find these technical bits scary. This builder worked great for me, I wanted to say thanks, many many thanks :) 2001:8003:7CCF:FC00:D408:6760:A405:E1A2 (talk) 00:45, 11 April 2020 (UTC)Reply

The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

My example wikifarm

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


I just wanted to share my setup of a wikifarm for a multi-language wiki using the same mediawiki installation. After a few days of trial and error I finally seem to have it working, but I didn't use any of the automatically generated scripts that probably wouldn't have worked in my case. In any case this is my setup.

  1. I have installed the mediawiki package in a subdomain, let's call it: https://mywiki.example.com
  2. After doing some initial customizations, I took the next step to make a wikifarm for different languages. I copied the "template" database tables of my initial installation to two other database tables with language suffixes ("_en" and "_it")
  3. I created two aliases in my apache vhost file, one for each of the languages that I will currently support:
    Alias /en/ /var/wikiinstallationpath
    Alias /it/ /var/wikiinstallationpath
  4. I added logic in the LocalSettings to pick up on the language based on the url "subdirectory":
    #Let's try to setup a wiki family
    if ( defined( 'MW_DB' ) ) {
        // Set $wikiId from the defined constant 'MW_DB' that is set by maintenance scripts.     $wikiId = MW_DB;
    } elseif (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] == 'mywiki.example.com' && substr($_SERVER['REQUEST_URI'], 0, 3) == '/en') {
        $wikiId = 'en';
    } elseif (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] == 'mywiki.example.com' && substr($_SERVER['REQUEST_URI'], 0, 3) == '/it') {
        $wikiId = 'it';
    } else {
        // Fail gracefully if no value was set to the $wikiId variable, i.e. if no wiki was determined
        die( 'It was not possible to determine the wiki ID.' );
    }
  5. Then I use that wikiID to choose the database:
    # MySQL specific settings $wgDBprefix = "";
    $wgDBname = 'mywiki_' . $wikiId;
    $wgSharedDB = 'mywiki';
    $wgCacheDirectory = "/tmp/mediawiki_".$wikiId."_cache";
    $wgUploadDirectory = "$IP/images";
    $wgUploadPath = "/images";
  6. Seeing that the language "subdirectories" are aliased to the script path by apache, I figure I can tell mediawiki that my script path is in the language subdirectory (physically non existent, virtually an alias of the real script path): $wgScriptPath = "/$wikiId";
    $wgScriptExtension = ".php";
    $wgArticlePath = "{$wgScriptPath}/$1";
    $wgUsePathInfo = true;
    $wgServer = "https://mywiki.example.com";
    ## The URL path to static resources (images, scripts, etc.)
    $wgResourceBasePath = $wgScriptPath;
  7. Then I have an .htaccess in my root directory:
    RewriteEngine On
    #For the time being we don't use the base hostname, if requested we redirect to the english version
    RedirectMatch ^/$ /en/
    #Let's do Short URLs
    RewriteCond %{HTTP_HOST} ^(mywiki.example.com)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php [L]

With this current setup, I am successfully serving my pages with short URLs, and the interwiki links are also being generated as short urls. Interwiki links between languages are working nicely too. Now that I've installed the Wikibase extension I just have to figure out how to populate the sites table and use sitelinks to link between my two languages. Lwangaman (talk) 01:33, 16 April 2020 (UTC)Reply

nice. how did it go with the wikibase after 7 months? :) Berot3 (talk) 15:59, 26 January 2021 (UTC)Reply
I have actually changed the setup since then. Something eventually went haywire after only a month or so, at first I thought it was spam but maybe it was jobs not being setup correctly. In any case the wiki suddenly stopped being accessible, and I really didn't know where to start to get it up and running again, so I just wiped it out and started all over. This time I followed the wikimedia style, which has the language wikis as third level domains; in my case, the language wikis are fourth level domains. Which in my opinion is a little less accessible than I would like it, but it works. I also made sure to read through everything that has to do with combating spam, and so I set up a few daily jobs to keep the antispam up to date. Wikibase is currently working well, and I have language links between the wikis working nicely. Lwangaman (talk) 17:13, 26 January 2021 (UTC)Reply
great! I also think that the mediawiki way for language isnt too bad :) Berot3 (talk) 17:32, 26 January 2021 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Running in a container

[edit]

I followed the guide, yet I can only get the articles under /wiki/ . I need to get the editing page options under /wiki/ aswell. If anyone can help I will appreciate it! 2601:8C1:8380:BC40:D3C:64CD:83E0:A6AC (talk) 07:34, 1 May 2020 (UTC)Reply

AliasMatch

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


I think this Manual for Apache should maybe be expanded:

using Alias is case-sensitive. Yes, in 97% of the cases this shouldnt be a issue, since everyone is onyl following links or using search.

but since Mediawiki itself is case-insensitive, why should also the alias?

For this we need AliasMatch:

AliasMatch (?i)^/wiki(.*) /path/to/your/webroot/w/index.php? Berot3 (talk) 13:47, 26 January 2021 (UTC)Reply

My bad. Mediawiki is not case-insensitive in general, it only is for the first capital letter by default.
There are extensions that could help, but nothing that I can recommend yet... Berot3 (talk) 15:05, 26 January 2021 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

This entire page is junk and needs deleting

[edit]

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/apache2.conf

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

.htaccess (many places)

LocalSettings.php

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

etc. 81.174.250.136 (talk) 15:11, 13 May 2021 (UTC)Reply

What it needs is editing, not deleting. This is a wiki, so any edit that improves the content is welcome. Ciencia Al Poder (talk) 16:08, 13 May 2021 (UTC)Reply
@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 (talk) 12:33, 24 May 2021 (UTC)Reply
@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. 2001:44C8:4400:7766:E5CD:F711:321B:495C (talk) 12:35, 24 May 2021 (UTC)Reply
I bet if you think it through and stop asking questions you'll find the answer here :-) Jonathan3 (talk) 12:43, 24 May 2021 (UTC)Reply
@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. 2001:44C8:4512:B6D6:A16F:69E9:F0A3:8BD9 (talk) 17:27, 24 May 2021 (UTC)Reply
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:
Type:
a2enmod
then when prompted type
rewrite
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 http://mywiki.com/index.php If your URLs look like http://mywiki.com/somefolder/index.php 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.
Done. Polymath uk (talk) 08:31, 2 July 2021 (UTC)Reply
Polymath you've been a lifesaver. Following your instructions got this done in about 10 seconds. Trying to use the incoherent instructions on the article itself had got me pulling my hair out after failing to make it work for an hour. Jcshy (talk) 06:59, 4 March 2024 (UTC)Reply
I used the script on redwerks.org, 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. 2A02:908:2057:7C80:4012:8145:F350:A140 (talk) 17:56, 8 August 2021 (UTC)Reply
Thank you so much
the "somefolder" tip solved de problem for me
Why you do not put this in the actual article? 83.97.188.172 (talk) 21:04, 14 February 2022 (UTC)Reply
I didn't realize I could edit the article! Polymath uk (talk) 16:52, 12 March 2022 (UTC)Reply
This advice doesn't seem to work anymore. While it rewrites the URL, it causes 404 errors and you can circumvent the rewrite rules by replacing /wiki/ with /index.php/ Met4lGod76 (talk) 00:50, 8 January 2025 (UTC)Reply
This means the rewrite rules aren't applied at all. MediaWiki is acting like they're in place, generating URLs that look pretty, but Apache isn't rewriting them (back to what they should point to). Either you forgot to restart/reload Apache, or your rules are wrong. Ciencia Al Poder (talk) 22:58, 8 January 2025 (UTC)Reply
I manged to get it to work after posting the comment. I don't believe it was an Apache issue, but rather a LocalSettings.php config issue (at least for my instance). Met4lGod76 (talk) 05:17, 10 January 2025 (UTC)Reply

Hello to the maintainers of this guide

[edit]

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. 2001:44C8:4405:657E:B5D6:B141:D388:F715 (talk) 13:49, 23 May 2021 (UTC)Reply

If you think it's hard to understand a 12-16 minute to read page, you may want to hire Professional development and consulting to take care of the configuration for you. Ciencia Al Poder (talk) 21:35, 23 May 2021 (UTC)Reply
@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. 2001:44C8:4487:7025:E86D:73EB:DB08:F62F (talk) 09:22, 24 May 2021 (UTC)Reply

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

[edit]

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.

Setup

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) --- shorturls.redwerks.org

  • 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.

2001:44C8:4512:B6D6:A16F:69E9:F0A3:8BD9 (talk) 20:49, 24 May 2021 (UTC) Reply

Added Template to flag major cleanup

[edit]

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)Reply

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. 2003:DE:F743:E8FF:149C:39B2:C753:C9C9 (talk) 19:14, 25 November 2021 (UTC)Reply
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? DanShearer (talk) 22:56, 4 February 2022 (UTC)Reply
You can edit without adding any translation tags, and someone with knowledge will add them when you're done Ciencia Al Poder (talk) 10:29, 5 February 2022 (UTC)Reply
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. DanShearer (talk) 21:18, 1 December 2021 (UTC)Reply
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 https://bugs.php.net/bug.php?id=31892" "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. Daniel Friesen (Dantman) (talk) 22:23, 18 February 2022 (UTC)Reply
Dantman - ack on the reasons for deprecating Alias, which themselves need to be mentioned when deprecating it and removing recipes. DanShearer (talk) 08:37, 22 February 2022 (UTC)Reply

rewrite module

[edit]

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

Type:

a2enmod

then when prompted type

rewrite

then press <enter> Rodion Proshin (talk) 09:19, 19 May 2022 (UTC)Reply

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

[edit]

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:

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

#   DO NOT EDIT. AUTOMATICALLY GENERATED.  USE INCLUDE FILES IF YOU NEED TO MAKE A CHANGE

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

>> 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

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d

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 root@server.yourprimarydomain.com [~]#

> 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) School4schools (talk) 16:26, 6 July 2022 (UTC)Reply

Missing information on some setups

[edit]

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.

http://localhost/mediawiki/index.php/Main_Page

but I wanted the pages to exist in

http://localhost/w/index.php/Main_Page

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/mod_rewrite.so 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.

http://localhost/w/index.php/Main_Page
http://localhost/wiki/Main_Page

Rdrg109 (talk) 01:57, 9 November 2022 (UTC) Reply

Rewrite rules in <Directory> are possible, but not the easiest way, and you won't be able to rewrite URLs outside of that directory
https://httpd.apache.org/docs/2.4/rewrite/intro.html#htaccess
If it works for you in <Directory>, it should work on <VirtualHost> too. Ciencia Al Poder (talk) 22:36, 9 November 2022 (UTC)Reply

References for the VisualEditor issue?

[edit]

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. Daniel Friesen (Dantman) (talk) 01:09, 19 December 2022 (UTC)Reply

It works, yet index.php still seen on navigation bar

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


I followed the process for my local wiki, and it works. Yet, the browser displays the rewritten URL.

Local wiki on my Mac Powerbook:

Scripts located on /Library/WebServer/Documents/wiki

I want to use the name of the wiki site: wikipapers.

After reconfiguring Apache (on httpd.conf) I can write:

http://localhost/wikipapers/Laplace_transform

Apache shows the proper page ... but ... on the navigation bar I still get

http://localhost/wiki/index.php/Laplace_transform


Are there any missing steps? Miguel.covas (talk) 16:12, 1 November 2023 (UTC)Reply

You're missing setting
$wgArticlePath = "/wikipapers/$1"; Ciencia Al Poder (talk) 17:21, 1 November 2023 (UTC)Reply
I reply to myself: I forgot to set $wgArticlePath to
"/wikipapers/$1".
Now it works fine. It also works using Alias ... Miguel.covas (talk) 18:01, 1 November 2023 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Using .htaccess to remove a range of subdirs

[edit]

(No luck on main mediawiki support desk)

I want to use replace an existing website with mediawiki, but to preserve incoming links I need to remove some path names using .htaccess

So https://subbrit.org.uk/sites/fan-bay-deep-shelter should become https://subbrit.org.uk/fan-bay-deep-shelter, ditto features and a few more

I already use the shortURL logic to shorten paths

LocalSettings.php

$wgScriptExtension = ".php";
$wgArticlePath = "/$1";
$wgUsePathInfo = true;
$wgScriptPath = "";

.htaccess

RewriteEngine On 
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f 
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d 
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/index.php [L]

But my attempts to add new rules like

RewriteRule ^sites/(.*)$ /$1 [R]

just don't take effect, it just asks if I want to create a new page Sites/fan-bay-deep-shelter. The rules do work on the server away from the wiki area. I worry that I'm just changing the URL, but mediawiki is working onm the underlying URI which is not changing Vicarage (talk) 14:06, 25 November 2023 (UTC)Reply

CSS broken, redirect to main page not working

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


Did everything according to the guide. Instead of redirecting to main page, accessing my domain (as well as */index.php) displays a page that contents a single "+" symbol and debug outputs if switched on, and nothing else.


Also, CSS broke after fiddling with short urls, now even if I undo everything I still have this error:

Refused to apply style from... because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.


Not asking for help, but the guide probably needs to be updated. 95.165.152.243 (talk) 20:05, 9 February 2024 (UTC)Reply

Never mind, my mistake entirely. Guide is OK, thanks for writing it! 95.165.152.243 (talk) 20:08, 9 February 2024 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Where to put RewriteRules when MediaWiki is installed in a nonstandard directory?

[edit]

For some reason, MediaWiki packaged for Debian installs in /usr/share/mediawiki instead of somewhere under /var/www. There is also no file for it in /etc/apache2/sites-available, only in /etc/apache2/conf-available. In which section of which file do the settings go in this case? I am trying to use the root access method and not a .htaccess file, to be clear. WarpedForest (talk) 02:10, 26 October 2024 (UTC)Reply

Files in <code>/etc/apache2/sites-available</code> are just Apache configuration files on how to serve the website using Virtual Hosts. Here's a guide on how to make a <code>.conf</code> file for Apache: <VirtualHost> Directive
Regardless of method, you need a site configuration file for the web server to display. Met4lGod76 (talk) 00:36, 8 January 2025 (UTC)Reply