media/) First, let's examine an URL. Here is an URL
http://www.example.com/foo/bar?x=toto&y=titi
It has 4 parts :
apache only rewrite the path. Apache can add things to the query string with its QSA flag. Apache can only add to the query string. It has no other possibility to change it.
So, how does it work ?
The PATH is compared with the first rule. if it matches, then it is rewritten. apache goes to the next rule. It compares the (maybe changed) PATH with this rule and, if it matches the PATH is modified. Apache goes on until there is no more rewrite rules. When this is done, apache has a new form of the url and deals with new URL.
Rules can do more than just rewriting the PATH. I just show 2 things that happen here :
It is important to note that this happens inside the apache server only. Your browser is not aware of this, and will never see the result of the rewriting rules.
example1 :
example 2 :
These are the default rules, presented in .htaccess.dist
lib/exe/fetch.php and we're doneRewriteRule ^_media/(.*) lib/exe/fetch.php?media=$1 [QSA,L]
Example and explanation: Given the URL http://example.com/_media/wiki:dokuwiki.png we have
^_media/(.*) that matches _media/wiki:dokuwiki.pnglib/exe/fetch.php?media=wiki:dokuwiki.png?media=wiki:dokuwiki.png part to be effectively added to the URL, we have to use the [QSA] flag[L] flag.http://example.com/lib/exe/fetch.php?media=wiki:dokuwiki.png
RewriteRule ^_detail/(.*) lib/exe/detail.php?media=$1 [QSA,L]
Example and explanation: This is the same as above, but with _details instead of _media.
RewriteRule ^_export/([^/]+)/(.*) doku.php?do=export_$1&id=$2 [QSA,L]
Example and explanation: This is almost the same as the preceding cases. The only difference is we have 2 groups of parentheses instead of 1. We'll have $1 and $2 as “variables”. So, given the URL http://example.com/_export/raw/wiki:syntax we have
_export/([^/]+)/(.*) that matches _export/raw/wiki:syntaxdoku.php?do=export_raw&id=wiki:syntax?do=export_raw&id=wiki:syntax part to be effectively added to the URL, we have to use the [QSA] flag[L] flag.http://example.com/doku.php?do=export_raw&id=wiki:syntax
http://example.com), give it to doku.php, and we're done.RewriteRule ^$ doku.php [L]
The resulting URL is
http://example.com/doku.php
RewriteCond %{REQUEST_FILENAME} !-f
and if it does not map to a folder
RewriteCond %{REQUEST_FILENAME} !-d
then give it to doku.php, and we're done
RewriteRule (.*) doku.php?id=$1 [QSA,L]
It transforms
http://example.com/faq:footerbuttons<code>into http://example.com/doku.php?id=faq:footerbuttons
[L] flag.RewriteRule ^index.php$ doku.php
It transforms
http://example.com/index.php<code>into http://example.com/doku.php
Here is presented the same information but more friendly
| initial URL | rewritten URL |
|---|---|
| (what apache will effectively deal with) | |
http://example.com/_media/wiki:dokuwiki.png | http://example.com/lib/exe/fetch.php?media=wiki:dokuwiki.png |
http://example.com/_details/wiki:dokuwiki.png | http://example.com/lib/exe/fetch.php?media=wiki:dokuwiki.png |
http://example.com/lib/image/page.png | No rewrite because lib/image/page.png is a file that exists. |
http://example.com/_export/raw/wiki:syntax | http://example.com/doku.php?do=export_raw&id=wiki:syntax |
http://example.com/index.php | http://example.com/doku.php |