Mod_rewrite with Wikka in subdirectory doesn't work


See also: ModRewrite

Symptoms

The installation path of Wikka (relative to the document root) is different from the path used to acess Wikka in the URL. Some examples might be:
Installation directory /www/wiki acessed via http://www.example.com/wiki/
Installation directory /wiki acessed via http://wiki.example.com/

Cause

If the path to the subdirectory is the same as the document root plus the subdirectory, the translation should work fine. However, if some kind of aliasing is taking place (as may be the case with hosted sites, though that is not the only possibility) then Apache won't be able to construct the correct URL without a little help.

Applies to

All Wikka versions
Note
Future versions of Wikka (> 1.1.6.0) may handle the workaround outlined below automatically.

Solution

Use the RewriteBase directive to tell Apache what the URL is for the directory Wikka is installled in. If, for example, Wikka is installed in the directory /www/wiki but it is acessed using http://www.example.com/wiki, you need to modify the .htacess file in the /www/wiki directory (starting with line 7):
  1. <IfModule mod_rewrite.c>
  2.  RewriteEngine on
  3.  RewriteCond %{REQUEST_FILENAME} -d
  4.  RewriteRule ^(.*/[^\./]*[^/])$ $1/
  5.  RewriteRule ^(.*)$ wikka.php?wakka=$1 [QSA,L]
  6. </IfModule>
and add a RewriteBase directive with the /wiki part of the URL:
  1. <IfModule mod_rewrite.c>
  2.  RewriteEngine on
  3.  RewriteBase /wiki
  4.  RewriteCond %{REQUEST_FILENAME} -d
  5.  RewriteRule ^(.*/[^\./]*[^/])$ $1/
  6.  RewriteRule ^(.*)$ wikka.php?wakka=$1 [QSA,L]
  7. </IfModule>

If you would rather add it to your Apache configuration file (httpd.conf), instead of .htaccess, you need to enclose it in a <Directory> and not use the RewriteBase directive:
<Directory /usr/local/www/data/wiki>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^(.*/[^\./]*[^/])$ $1/
  RewriteRule ^(.*)$ wikka.php?wakka=$1 [QSA,L]
</Directory>
where the path /usr/local/www/data/wiki corresponds to the absolute server path where your Wikka is installed (change to match your configuration).


CategoryWorkaround
Comments
Comment by ChristianBarthelemy
2005-02-15 13:33:22
I have tried both solutions with the RewriteBase directive or within the httpd.conf and still have the same unexplained problem:
All is working perfectly except that when I try to create a new page by forcing the url to http://wikka.jsnx.com/NewPage the system proposes me to create newpage instead of NewPage. Same problem using the action {{newpage}} or when trying to create NewPage from an existing wikka page.
I have really no idea where it could come from. Any suggestion welcome.
Comment by JavaWoman
2005-02-17 07:31:37
@Christiaan,
I think you mentioned this problem before (can't search comments), but we didn't figure it out. What OS is your Wikka running on? I'm wondering if it could be Windows doing this, or some setting in your httpd.conf.
Comment by ChristianBarthelemy
2005-02-17 18:23:46
Yet I already explained this problem in the ModRewrite page.
I have a windows 2k/apache/mysql base. The problem could come from my httpd.conf althrough I cannot identify anything wrong.
Comment by JavaWoman
2005-02-20 11:39:59
Christian,
Sorry, I just could not remember *where* we discussed it. Just did some more digging and probably found a clue; see the added a comment to the discussion on the ModRewrite page. Hope that helps!
Comment by TriAthlon
2006-09-30 03:32:34
It may or may not help anyone else but I couldn't for the life of me get my Rewrite rules to work. I tried them in the .htaccess file and I tried them in the httpd.conf file. Nothing would work. However after I added the AllowOverride directive to my <Directory> entry in httpd.conf life was good and it's redirecting like it should now.

I hope this saves someone from banging their head like I have been for the last couple of hours.
Comment by DarTar
2006-10-03 04:29:50
Hi TriAthlon, you're right that it should be mentioned here that there's not much you can do to activate rewrite rules if the server configuration doesn't allow you to. I hope that with the new installer that is about be included in 1.1.7 things are going smoother.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki