Also available in //((../Deutsch/RewriteModus Deutsch))//
{{toc numerate=1}}
===Apache mod_rewrite===
====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 [[https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html Apache Module Homepage]].
So what does it to WackoWiki?
1. mod_rewrite enabled:
* ##~http://www.example.com/Download##
2. mod_rewrite disabled:
* ##~http://www.example.com/?page=Download##
====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%%
=====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 ((https://httpd.apache.org/docs-2.4/mod/core.html#allowoverride .htaccess files are ignored)).
%%AllowOverride All%%
====.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).
%%(info type="note")
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.
%%
====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!
====Special cases====
special .htaccess files
=====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
1. http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
2. bugs:397#bugnotes
===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;
}
%%
{{backlinks}}