Mod_rewrite not working for apache alias

apache-2.2dekiwikimod-rewriterewrite

I have created a documentation wiki that i want to attach to my main site using an Alias for the virtual host. This allows me to access the wiki by going to website.com/documentation. I have successfully used mod_rewrite in the past for an alias, but i cannot get this one to work. The Alias is setup correctly as the site is working, but no rewrite rules do.

Im using doku wiki, but it should matter what im using as apache does all the work not php. I want to rewrite the url as follows.

http://website.com/documentation/doku.php?id=start

http://website.com/documentation/start

The below rewrite rules are meant to be the default out of the box rules that work for dokuwiki, but they aren't doing anything.

RewriteEngine On    
RewriteRule ^_media/(.*)              lib/exe/fetch.php?media=$1  [QSA,L]
RewriteRule ^_detail/(.*)             lib/exe/detail.php?media=$1  [QSA,L]
RewriteRule ^_export/([^/]+)/(.*)     doku.php?do=export_$1&id=$2  [QSA,L]
RewriteRule ^$                        doku.php  [L]
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule (.*)                      doku.php?id=$1  [QSA,L]
RewriteRule ^index.php$               doku.php

I tried adding the usual rules that im familiar with and neither of these worked either.

RewriteRule ^documentation/([^/]*)$ /documentation/doku.php?id=$1 [L]
RewriteRule ^([^/]*)$ /doku.php?id=$1 [L]

When i go to http://website.com/documentation/start in the browser i get a 404 error.

The requested URL /documentation/start was not found on this server.

Best Answer

First, check if you enabled .htaccess in your Apache config with AllowOverride all for your website path

https://httpd.apache.org/docs/2.4/en/howto/htaccess.html

Then I think you are looking for this :

https://wiki.apache.org/httpd/RewriteQueryString

RewriteCond %{QUERY_STRING} ^/documentation/doku.php?id=(.*)
RewriteRule .* /documentation/%1/ [L,R=301]
RewriteRule ^/documentation/(.*)/ /documentation/doku.php?id=$1 [L]

Note that %1 is used instead of $1 to catch the result of RewriteCond regexp

Like that /documentation/doku.php?id=start will show /documentation/start/ and will serve page /documentation/doku.php?id=start

In your Rewrite rule you forget the / at the start of your regexp

RewriteRule ^/documentation/(.*)/ /documentation/doku.php?id=$1 [L]
Related Topic