meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
wiki:dokuwiki-rewrite-rules [21/05/2019 08:25] – créée - modification externe 127.0.0.1wiki:dokuwiki-rewrite-rules [30/07/2023 08:10] (current) – [Default rules explained] ztrulphcs
Line 46: Line 46:
 These are the default rules, presented in ''.htaccess.dist'' These are the default rules, presented in ''.htaccess.dist''
  
-  - if PATH starts with _media/, give it lib/exe/fetch.php and we're done<code>+  - if PATH starts with _media/, give it to ''lib/exe/fetch.php'' and we're done<code>
 RewriteRule ^_media/(.*)              lib/exe/fetch.php?media=$1  [QSA,L] RewriteRule ^_media/(.*)              lib/exe/fetch.php?media=$1  [QSA,L]
 +</code>Example and explanation: Given the URL ''%%http://example.com/_media/wiki:dokuwiki.png%%'' we have
 +    * ''^_media/(.*)'' that matches ''_media/wiki:dokuwiki.png''
 +      * The part corresponding to ''(.*)''((that means all the characters that are left. (after ''media/'') )) is associated with ''$1''. So ''$1'' is now ''wiki:wiki.png''.
 +    * it is rewritten as ''lib/exe/fetch.php?media=wiki:dokuwiki.png''
 +      * Note that for the ''?media=wiki:dokuwiki.png'' part to be effectively added to the URL, we have to use the ''[QSA]'' flag
 +    * Our job is done. ie no need to test for the next rewrite rule. Since this rule applied, it is the **L**ast one in this run. That's the role of the ''[L]'' flag.
 +    * In the end, apache now has to deal with this URL:<code>
 +http://example.com/lib/exe/fetch.php?media=wiki:dokuwiki.png
 </code> </code>
   - if PATH starts with _details/, give it to lib/exe/detail.php and we're done<code>   - if PATH starts with _details/, give it to lib/exe/detail.php and we're done<code>
 RewriteRule ^_detail/(.*)             lib/exe/detail.php?media=$1  [QSA,L] RewriteRule ^_detail/(.*)             lib/exe/detail.php?media=$1  [QSA,L]
-</code> +</code>Example and explanation: This is the same as above, but with ''_details'' instead of ''_media''. 
-  - if PATH starts with _export/FOO/, give it to doku.php?do=export_FOO and we're done<code>+  - if PATH starts with _export/**FOO**/, give it to doku.php?do=export_**FOO** and we're done<code>
 RewriteRule ^_export/([^/]+)/(.*)     doku.php?do=export_$1&id=$2  [QSA,L] RewriteRule ^_export/([^/]+)/(.*)     doku.php?do=export_$1&id=$2  [QSA,L]
 +</code>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:syntax''
 +      * The part corresponding to ''([^/]*)''((that means the first word left after ''_export/'')) is associated with ''$1''. So ''$1'' is now ''raw''.
 +      * The part corresponding to ''(.*)''((that means everything that's left (after ''_export/raw/'') )) is associated with ''$2''. So ''$2'' is now ''wiki:syntax''.
 +    * it is rewritten as ''doku.php?do=export_raw&id=wiki:syntax''
 +    * Note that for the ''?do=export_raw&id=wiki:syntax'' part to be effectively added to the URL, we have to use the ''[QSA]'' flag
 +    * Our job is done. ie no need to test for the next rewrite rule. Since this rule applied, it is the **L**ast one in this run. That's the role of the ''[L]'' flag.
 +    * In the end, apache now has to deal with this URL:<code>
 +http://example.com/doku.php?do=export_raw&id=wiki:syntax
 </code> </code>
-  - if PATH is empty (ie full URL is just http://www.example.com), give it to doku.php, and we're done.<code>+  - if PATH is empty (ie full URL is just ''%%http://example.com%%''), give it to doku.php, and we're done.<code>
 RewriteRule ^$                        doku.php  [L] RewriteRule ^$                        doku.php  [L]
 +</code>The resulting URL is <code>
 +http://example.com/doku.php
 </code> </code>
   - if the PATH does not map to a file<code>   - if the PATH does not map to a file<code>
Line 64: Line 83:
 </code> then give it to doku.php, and we're done<code> </code> then give it to doku.php, and we're done<code>
 RewriteRule (.*)                      doku.php?id=$1  [QSA,L] RewriteRule (.*)                      doku.php?id=$1  [QSA,L]
 +</code>It transforms <code>
 +http://example.com/faq:footerbuttons<code>into
 +http://example.com/doku.php?id=faq:footerbuttons
 </code> </code>
   - Because of the tests performed in 5, we are sure that from here on, we deal with an existing file or folder.   - Because of the tests performed in 5, we are sure that from here on, we deal with an existing file or folder.
-  - if the url/file is index.php, then use doku.php instead of index.php and continue with next rule.<code>+  - if the url/file is index.php, then use doku.php instead of index.php and continue with next rule, as there is no ''[L]'' flag.<code>
 RewriteRule ^index.php$ doku.php RewriteRule ^index.php$ doku.php
-</code>+</code>It transforms <code> 
 +http://example.com/index.php<code>into 
 +http://example.com/doku.php</code>
   - There is no more rule, so no special rewrite => just serve the file or folder as usual.   - There is no more rule, so no special rewrite => just serve the file or folder as usual.
 +
 +
 +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%%''  |