DokuWiki

It's better when it's simple

User Tools

Site Tools


rewrite

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rewrite [2015-05-07 22:48] – [Apache] 75.148.84.233rewrite [2024-03-13 11:51] (current) – link to up2date apache2 doc 185.177.84.1
Line 1: Line 1:
 ====== URL Rewriting ====== ====== URL Rewriting ======
- 
-FIXME This page is a mess and should be rewritten. 
  
 By default, DokuWiki does no URL rewriting, resulting in URLs like this: By default, DokuWiki does no URL rewriting, resulting in URLs like this:
  
-  http://example.com/doku.php?id=page+  http://example.com/doku.php?id=wiki:syntax
      
-These URLs are considered ugly and are not indexed well by some search engines. +These URLs are somewhat ugly and might not be indexed well by some search engines. URL rewriting offers a solution to this, resulting in nicer URLs. 
 + 
 +===== Rewriting options =====
  
-The solution is to enable URL rewriting, which is disabled by default. DokuWiki supports two methods for URL rewriting, enabled through the [[config:userewrite]] option. One relies on the rewriting capabilities of the webserver; the other one handles rewritten URLs inside DokuWiki. The table below summarizes these options.+DokuWiki supports two methods for URL rewriting, enabled through the [[config:userewrite]] option. One relies on the rewriting capabilities of the webserver; the other one handles rewritten URLs inside DokuWiki. The table below summarizes these options.
  
 ^ Value ^ Info ^ Example URL ^ ^ Value ^ Info ^ Example URL ^
Line 18: Line 18:
 URL-Rewriting is disabled by default because it requires some additional configuration besides setting the appropriate [[config:userewrite|config option]] - these configs are discussed below. URL-Rewriting is disabled by default because it requires some additional configuration besides setting the appropriate [[config:userewrite|config option]] - these configs are discussed below.
  
-URL-Rewriting can be enabled at ''?do=admin&page=config#_advanced'' or in the local conf/local.php file line that reads ''$conf['userewrite'N;''. N is the number 0, 1, or 2. The default is zero without this line present. Follow the configuration instructions below for whichever option is chosen.+==== Option 1: web server ====
  
-====== Option 1: web server ====== 
  
-:!: Remember to set following in the Configuration Manager ''/start?do=admin&page=config'' 
-  * Use nice URLs: **.htaccess** 
-  * Use slash as namespace separator in URLs [**x**] 
-Otherwise rewrite rules will not be useful. 
  
-==== Apache ====+This option requires some setup in the webserver first. How to enable it, depends on the webserver used. Please refer to the linked pages below for additional info.
  
-Rewriting URLs in Apache is done through the **mod_rewrite** module of [[http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html|Apache 1]] or [[http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html|Apache 2]].+  * [[install:Apache]] -- uses the [[http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html|mod_rewrite]] module. It can be enabled using a ''.htaccess'' file. 
 +  * [[install:IIS]] -- uses custom rewrite rules or the rewrite module 
 +  * [[install:nginx]] -- has built in rewriting support 
 +  * [[install:php-webserver|PHP's built-in web server]] -- needs no configuration, rewrite will work using DokuWiki's index.php router
  
-DokuWiki comes with an ''.htaccess.dist'' file which contains the needed rewrite rules for mode 1. 
  
-Here is an example +Once the rewriting support has been enabled in the web server, this option can be enabled in the DokuWiki configuration.
-<code apache> +
-RewriteEngine on+
  
-RewriteBase /dokuwiki+Select the ''.htaccess'' option in the [[config:userewrite]] config dropdown. Alternatively, in your ''conf/local.php'' file, add or modify the line so it reads:
  
-RewriteRule ^_media/(.*)              lib/exe/fetch.php?media=$1  [QSA,L] +<code php> 
-RewriteRule ^_detail/(.*)             lib/exe/detail.php?media=$1  [QSA,L] +$conf['userewrite'] = 1;
-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+
 </code> </code>
  
-On the line ''RewriteBase /dokuwiki'', you may need to replace the ''/dokuwiki'' with whatever directory you use in your URL to get to the wiki If your wiki appears at the top level of the domain (e.g. http://example.com points to the start page of the wiki then use the following line: ''RewriteBase /''.+In DokuWiki root folder, find the file ''.htaccess.dist'' and copy it as ''.htaccess''. Edit it and uncomment lines referring to userwrite. It's a short file and easy to understand. 
 +==== Option 2DokuWiki ====
  
-You may also need to rename the file from ''.htaccess.dist'' to ''.htaccess''. 
  
-== Apachectl status broken ==+This option won't need any webserver setup. However it relies on the PATH_INFO feature of the CGI standard as implemented by Apache. Some webserver configurations might not support it.
  
-Dokuwiki rewrite rule effect //apachectl status// command and make it return dokuwiki 404 page instead of the server-status page. You can fix that by either putting this in dokuwiki rewrite rules +To enable this option, select the ''DokuWiki internal'' option in the [[config:userewrite]] config dropdownAlternatively, in your ''conf/local.php'' file, add or modify the line so it reads:
- +
-  RewriteCond %{REQUEST_URI} !^/server-status$ +
- +
-or creating an empty server-status file in dokuwiki root folder where doku.php is located. see forum post [[http://forum.dokuwiki.org/post/32858 | Apachectl status is broken with dokuwiki]] +
- +
-==== IIS ==== +
-Enable url rewriting and insert appropriate set of rules: +
- +
-<code iis> +
-<rewrite> +
-<rules> +
-  +
-<rule name="rule 1C" stopProcessing="true"> +
- <match url="^_media/(.*)" /> +
- <action type="Rewrite" url="/lib/exe/fetch.php?media={R:1}" appendQueryString="true" /> +
-</rule> +
-<rule name="rule 2C" stopProcessing="true"> +
- <match url="^_detail/(.*)" /> +
- <action type="Rewrite" url="/lib/exe/detail.php?media={R:1}" appendQueryString="true" /> +
-</rule> +
-<rule name="rule 3C" stopProcessing="true"> +
- <match url="^_export/([^/]+)/(.*)" /> +
- <action type="Rewrite" url="/doku.php?do=export_{R:1}&amp;id={R:2}" appendQueryString="true" /> +
-</rule> +
-<rule name="rule 4C" stopProcessing="true"> +
- <match url="^$" /> +
- <action type="Rewrite" url="/doku.php" /> +
-          <conditions> +
-            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> +
-            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> +
-           </conditions> +
-</rule> +
-<rule name="rule 5C" stopProcessing="true"> +
- <match url="(.*)" /> +
- <action type="Rewrite" url="/doku.php?id={R:1}" appendQueryString="true" /> +
-          <conditions> +
-            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> +
-            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> +
-          </conditions> +
-</rule> +
-<rule name="rule 6C"> +
- <match url="^index.php$" /> +
- <action type="Rewrite" url="/doku.php" /> +
-</rule> +
-</rules> +
-</rewrite>+
  
 +<code php>
 +$conf['userewrite'] = 2;
 </code> </code>
  
-> Where should I put that rules?! 
  
-=== IIS 7.0 or greater === 
-IIS 7.0 and above can be extended with a the URL Rewrite module 2.0 available from Microsoft for both [[http://go.microsoft.com/?linkid=9722533|x86]] and [[http://go.microsoft.com/?linkid=9722532|x64]]  
- 
-Save the Apache rules above to a .htaccess file removing the "RewriteBase /dokuwiki" line. This will not be required as we will be adding the rules directly to the root of the wiki. 
- 
-In IIS Manager select your Wiki folder, and under IIS select "URL Rewrite" (if you had Manager open before installing, a refresh will be required)  
- 
-In the actions pane on the right hand side, choose "Import Rules" 
- 
-For your configuration file, select the .htaccess file and Import, this should give you 6 converted rules. 
- 
-Finally hit Apply in the Actions panel on the right hand side. 
- 
-Configure your Wiki to use .htaccess rules for rewrite and you should now be seeing your URLs rewritten. 
- 
-==== Nginx ==== 
- 
-See [[http://nginx.org/|nginx]] [[http://wiki.nginx.org/|documentation]]. In the following example, our server root is /var/www, and we extract dokuwiki to /var/www/wiki. 
- 
-<code> 
-server { 
-    listen 80; 
-    server_name example.com www.example.com; 
- 
-    #maximum file upload size is 4MB - change accordingly if needed 
-    client_max_body_size 4M; 
-    client_body_buffer_size 128k; 
- 
-    root /var/www/wiki; 
-    index doku.php; 
- 
-    location / { try_files $uri $uri/ @dokuwiki; } 
- 
-    location @dokuwiki { 
-        rewrite ^/_media/(.*) /lib/exe/fetch.php?media=$1 last; 
-        rewrite ^/_detail/(.*) /lib/exe/detail.php?media=$1 last; 
-        rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2 last; 
-        rewrite ^/(?!lib/)(.*) /doku.php?id=$1&$args last; 
-    } 
- 
-    location ~ \.php$ { 
-        if (!-f $request_filename) { return 404; } 
-        include fastcgi_params; 
-        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
-        fastcgi_param REDIRECT_STATUS 200; 
-        fastcgi_pass 127.0.0.1:9000; 
-    } 
-} 
-</code> 
- 
-=== Notes === 
- 
-If using https the HTTPS server variable has to be set to allow propper linking in dokuwiki. This can be done 
-in the server section with: 
- 
-  fastcgi_param HTTPS on; 
- 
-The last keyword of rewrite rules before location setup make sure that rewrite only happens once. You should replace all /dokuwiki/ appeared above to you wiki directory relative to web server root directory. 
- 
-If you are copy-pasting these configs, make sure you are adding locations to secure some of the directories as described on [[security|Security]] page. 
- 
-====== Option 2: DokuWiki ====== 
- 
-In your conf/local.php file, add or modify the line so it reads: 
- 
-| $conf['userewrite'] = 2; | 
- 
-This option won't need any webserver setup. However it relies on the PATH_INFO feature of the CGI standard as implemented by Apache. IIS is [[bug>718|known not to work]] with this setting. 
  
 ===== Clean PHP session ID ===== ===== Clean PHP session ID =====
Line 198: Line 74:
 </code> </code>
  
-====== Also see ======+====== See Also ====== 
   * [[:tips:httpslogin|Rewrite rules for secure login]]   * [[:tips:httpslogin|Rewrite rules for secure login]]
 +  * [[https://stackoverflow.com/questions/9153262/tips-for-debugging-htaccess-rewrite-rules | Tips for debugging .htaccess rewrite rules]]
 +
rewrite.1431031727.txt.gz · Last modified: 2015-05-07 22:48 by 75.148.84.233

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki