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
Next revisionBoth sides next revision
rewrite [2017-08-29 17:39] – [Apache] 81.133.88.36rewrite [2022-12-29 15:24] – [Also see] Michaelsy
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:
Line 16: Line 14:
  
   - Go to Admin   - Go to Admin
-  - Open Configuration Manager+  - Open Configuration Settings
   - Change Nice URLs option to .htaccess (use find, it's far down)   - Change Nice URLs option to .htaccess (use find, it's far down)
   - Underneath it, check the option to "Use slash as namespace separator in URLs"   - Underneath it, check the option to "Use slash as namespace separator in URLs"
Line 97: Line 95:
 Dokuwiki rewrite rule affect //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 Dokuwiki rewrite rule affect //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
  
-  RewriteCond %{REQUEST_URI} !^/server-status$+<code apache> 
 +RewriteCond %{REQUEST_URI} !^/server-status$ 
 +</code>
  
 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]] 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]]
Line 107: Line 107:
 Enable url rewriting and insert appropriate set of rules: Enable url rewriting and insert appropriate set of rules:
  
-<code iis>+<code xml>
 <rewrite> <rewrite>
 <rules> <rules>
Line 148: Line 148:
 </code> </code>
  
-**If you are using Azure Web App**, just put this lines under inside the <system.webServer> tags in web.config file (situated in wwwroot of your App.+**If you are using Azure Web App**, just put these lines under the <system.webServer> tags in web.config file (situated in wwwroot of your App).
  
-> Where should I put that rules?! 
  
 === IIS 7.0 or greater === === IIS 7.0 or greater ===
Line 171: Line 170:
 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. 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>+<code nginx>
 server { server {
     listen 80;     listen 80;
Line 189: Line 188:
         rewrite ^/_detail/(.*) /lib/exe/detail.php?media=$1 last;         rewrite ^/_detail/(.*) /lib/exe/detail.php?media=$1 last;
         rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2 last;         rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2 last;
-        rewrite ^/(?!lib/)(.*) /doku.php?id=$1&$args last;+        rewrite ^/(.*) /doku.php?id=$1&$args last;
     }     }
  
Line 207: Line 206:
 in the server section with: in the server section with:
  
-  fastcgi_param HTTPS on;+<code nginx> 
 +fastcgi_param HTTPS on; 
 +</code>
  
 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. 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. 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.
 +
 +==== httpd (OpenBSD) ====
 +See also [[https://man.openbsd.org/httpd.conf.5|httpd documentation]]. By default the server root is /var/www and dokuwiki is in /var/www/dokuwiki
 +
 +<code autoconf>
 +server "default" {
 +  listen on egress port 443
 +  root "/dokuwiki"
 +  directory index doku.php
 +  
 +  # Set according to upload_max_filesize and post_max_size in php.ini  
 +  connection max request body 20971520  
 +
 +  location "*.php"     { fastcgi socket "/run/php-fpm.sock" }
 +  
 +  # Block access to non-public dirs
 +  location "/data/*"   { block }
 +  location "/conf/*"   { block }
 +  location "/bin/*"    { block }
 +  location "/inc/*"    { block }
 +  location "/vendor/*" { block }
 +    
 +  # URL rewrite rules  
 +  location match "/media/(.*)" {
 +    request rewrite "/lib/exe/fetch.php?media=%1"
 +  }
 +    
 +  location match "/detail/(.*)" {
 +    request rewrite "/lib/exe/detail.php?media=%1"
 +  }
 +    
 +  location match "/export/([^/]+)/(.*)" {
 +    request rewrite "/doku.php?do=export_%1&id=%2"
 +  }
 +
 +  location match "/(lib/.*)" {
 +    request rewrite "/%1"
 +  }
 +
 +  location match "/([^lib])" {
 +    request rewrite "/doku.php?id=$DOCUMENT_URI&$QUERY_STRING"
 +  }
 +}
 +</code>
  
 ====== Option 2: DokuWiki ====== ====== Option 2: DokuWiki ======
Line 217: Line 262:
 In your conf/local.php file, add or modify the line so it reads: In your conf/local.php file, add or modify the line so it reads:
  
-$conf['userewrite'] = 2; |+<code php> 
 +$conf['userewrite'] = 2; 
 +</code>
  
 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. However, new IIS versions seem to work with this. 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. However, new IIS versions seem to work with this.
Line 243: Line 290:
  
 ====== Also see ====== ====== Also see ======
 +
   * [[: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.txt · Last modified: 2024-03-13 11:51 by 185.177.84.1

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