Topic on Manual talk:Short URL/Apache

Payo (talkcontribs)

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.
Dantman (talkcontribs)
  • 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.
Payo (talkcontribs)

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?

Dantman (talkcontribs)

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]
Payo (talkcontribs)

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 (talkcontribs)

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

Dantman (talkcontribs)

Could you show what config you're using now?

Payo (talkcontribs)
Payo (talkcontribs)

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. :-)

Dantman (talkcontribs)

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.

Payo (talkcontribs)

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 (talkcontribs)

-