Manual talk:Short URL/Apache

From MediaWiki.org
Jump to: navigation, search

Contents

Thread titleRepliesLast modified
AllowOverride All1217:59, 19 May 2013
DOCUMENT_ROOT405:40, 13 April 2013
More straight explanations121:42, 20 March 2013
what one of the rewrite rules actually does on different versions of Apache009:40, 31 January 2013
$wgArticlePath115:39, 18 January 2013

AllowOverride All

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

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

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:

  • Reinstall files from source the normal way
  • or, swap %{DOCUMENT_ROOT}/mediawiki for /var/lib/mediawiki
  • or, try swapping %{DOCUMENT_ROOT}/mediawiki for mediawiki and changing [L] for [L,PT]
Daniel Friesen (Dantman) (talk)12:32, 18 May 2013
 

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

sudo a2enmod rewrite fixed that. But no I am still getting the short url with a 404.

Payo (talk)12:55, 18 May 2013

Could you show what config you're using now?

Daniel Friesen (Dantman) (talk)12:57, 18 May 2013
 
 
 
 
 

DOCUMENT_ROOT

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)

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

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

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

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

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
 
 
 
 

More straight explanations

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

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
 

what one of the rewrite rules actually does on different versions of Apache

The rule 'RewriteRule ^/*$ %{DOCUMENT_ROOT}/mediawiki/index.php [L]' seems to work on Apache 2 to redirect hostname/wiki_folder to hostname/wiki_URL_path. On Apache 1, which is still the default on one (probably all) the main BSD distros (though you can install an Apache 2 package--it is just recommended not to install any other packages than the base system unless you absolutely need their functions,) the rule seems to redirect the root of one's entire site to the wiki. Please be clear about what these rules do and give recommendations that will work for both main versions of Apache.'

Dchmelik (talk)08:53, 31 January 2013

$wgArticlePath

"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

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