Manual talk:Short URL/Apache
- [History↑]
Contents
| Thread title | Replies | Last modified |
|---|---|---|
| AllowOverride All | 12 | 17:59, 19 May 2013 |
| DOCUMENT_ROOT | 4 | 05:40, 13 April 2013 |
| More straight explanations | 1 | 21:42, 20 March 2013 |
| what one of the rewrite rules actually does on different versions of Apache | 0 | 09:40, 31 January 2013 |
| $wgArticlePath | 1 | 15:39, 18 January 2013 |
I am a bit confused:
- I want to use
/wiki/Page_title - I have root access (on a cloud server running Ubuntu 13.04) and would prefer NOT to use an .htaccess file
- 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:
- go to edit the
/etc/apache2/sites-available/defaultfile. - 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/defaultbutAllowOverride Allit appears several times there. Do I change them all or just one? I change them all, and save. - I change the LocalSettings.php file as instructed
Apache2 -k restartwon´t work- rebooting the server results in a correctly formed Short_url but the wiki itself is brokemn.
- 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.
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?
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}/mediawikidoesn'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}/mediawikifor/var/lib/mediawiki - or, try swapping
%{DOCUMENT_ROOT}/mediawikiformediawikiand changing[L]for[L,PT]
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? :-(
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.
%{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.
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?
%{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.
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.)
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
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.
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.'
"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= .
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.