Mod Rewrite
Also available in Deutsch
1. Apache mod_rewrite
1.1. Basics
This is a module for the Apache webserver and rewrites requested URLs on the fly. It operates both in per-server context (Apache v2.x: apache2.conf
) and per-directory context (.htaccess
). Detailed informations can be found on the Apache Module Homepage.
So what does it to WackoWiki?
- mod_rewrite enabled:
-
http://www.example.com/Download
-
- mod_rewrite disabled:
-
http://www.example.com/?page=Download
-
1.2. Howto enable mod_rewrite
Of course, you need an Apache webserver WackoWiki is running on, and the module mod_rewrite has to be installed and activated.
mod_rewrite in your Apache configuration file (http.conf oder apache2.conf):
/apache/conf/http.conf
deactivated
#LoadModule rewrite_module modules/mod_rewrite.so
activated:
LoadModule rewrite_module modules/mod_rewrite.so
1.2.1. AllowOverride All
Make sure that your .htaccess files are not ignored: in your apache configuration file (http.conf or apache2.conf), make sure that for the directory where the wiki is:
AllowOverride None
is not set. Because then .htaccess files are ignored.
AllowOverride All
1.3. .htaccess
If you have no privileges to edit the apache2.conf (e.g. you rent webspace) or simply you don't want to, you have to use the .htaccess
-method (don't forget the dot!) with the following content:
# No user serviceable parts inside # If you want to fix anything by tuning htaccess - you're possibly on the wrong path <IfModule mod_env.c> SetEnv HTTP_MOD_ENV on </IfModule> <IfModule mod_rewrite.c> <IfModule mod_env.c> SetEnv HTTP_MOD_REWRITE on </IfModule> RewriteEngine on RewriteRule ^ index.php [QSA,L] </IfModule> <IfModule !mod_rewrite.c> <FilesMatch \.php$> # Apache 2.4 <IfModule mod_authz_core.c> Require all denied </IfModule> # Apache 2.2 <IfModule !mod_authz_core.c> Order Allow,Deny Deny from all </IfModule> </FilesMatch> <FilesMatch "^(admin|index)\.php$"> # Apache 2.4 <IfModule mod_authz_core.c> Require all granted </IfModule> # Apache 2.2 <IfModule !mod_authz_core.c> Order Allow,Deny Allow from All Deny from None </IfModule> </FilesMatch> </IfModule>
This file is shipped with the WackoWiki package you downloaded, you find this file inside the Wacko folder. If you can't find it, just create it (Permission: -rwxr-xr-x).
Any rules that you can put in an .htaccess
file can be also put directly into server configuration files. In fact, the official Apache documentation recommends using server configuration files instead of .htaccess
because Apache processes it faster that way.
However setting rules in
.htaccess
is convenient, especially with multiple websites on the same server. It does not require a server restart for changes to take effect and it does not require root privileges to edit those rules, simplifying maintenance and making changes possible with an unprivileged account.
1.4. httpd.conf / apache2.conf
If you want to edit the httpd.conf
/ apache2.conf
file directly, please make sure to delete or rename the .htaccess
in your Wacko folder.
Now add the following lines to your configuration file:
#Wacko URL-rewriting Options Indexes Includes FollowSymLinks MultiViews AllowOverride All RewriteEngine on RewriteRule ^ index.php [QSA,L] Order allow,deny Allow from all
Restart your webserver to enable the modifications!
1.5. Special cases
special .htaccess files
1.5.1. RewriteBase
If your webserver's URLs are not directly related to physical file paths, you will need to use RewriteBase in every .htaccess file where you want to use RewriteRule directives.
RewriteBase /
RewriteBase /folder/
e.g. .htaccess
<IfModule mod_rewrite.c> RewriteEngine on RewriteBase /folder/ </IfModule>
related
2. Nginx rewrite
In rewrite mode, nginx setting will affect the URL of admin panel. The following code can be used.
In other locales, parse the URL
if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /index.php; }