rewrite
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rewrite [2014-04-29 15:37] – 207.172.223.242 | rewrite [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:// | + | |
+ | |||
+ | 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. | ||
- | These URLs are considered ugly and are not indexed well by some search engines. | + | ===== Rewriting options ===== |
- | The solution is to enable URL rewriting, which is disabled by default. | + | DokuWiki supports two methods for URL rewriting, enabled |
^ 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: | URL-Rewriting is disabled by default because it requires some additional configuration besides setting the appropriate [[config: | ||
- | **Nota Bene** In all the following examples, add or modify the line in your conf/ | + | ==== Option 1: web server ==== |
- | | $conf[' | ||
- | where N is the number 1 or 2. (No need to do anything if you want the option 0.) | ||
- | ===== Option 0: editing php code and filenames ===== | + | 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. |
- | This is not about URL rewrite but when you need to replace | + | * [[install: |
+ | * [[install: | ||
+ | * [[install: | ||
+ | * [[install: | ||
- | * If you want: Change folder name (default is ' | ||
- | * If you want: Change default filename ' | ||
- | - Update filename in file ' | ||
- | - Update filename in < | ||
- | if(!defined(' | ||
+ | Once the rewriting support has been enabled in the web server, this option can be enabled in the DokuWiki configuration. | ||
- | That's all! | + | Select the '' |
- | If you find one more php file to edit, note it here, please. | + | < |
- | + | $conf['userewrite'] = 1; | |
- | Regards | + | |
- | Bronek | + | |
- | ===== Option 1: web server ===== | + | |
- | + | ||
- | :!: Remember to set following in the Configuration Manager | + | |
- | * Use nice URLs: **.htaccess** | + | |
- | * Use slash as namespace separator in URLs [**x**] | + | |
- | Otherwise rewrite rules will not be useful. | + | |
- | + | ||
- | + | ||
- | ==== Hiawatha ==== | + | |
- | → [[install: | + | |
- | ==== Apache ==== | + | |
- | + | ||
- | Rewriting URLs in Apache is done through the **mod_rewrite** module of [[http:// | + | |
- | + | ||
- | <code apache> | + | |
- | LoadModule rewrite_module modules/ | + | |
</ | </ | ||
- | On many kinds of Linux (Ubuntu, Debian, etc) you may enable mod_rewrite with: | + | In DokuWiki root folder, find the file '' |
+ | ==== Option 2: DokuWiki ==== | ||
- | <code bash> | ||
- | sudo a2enmod rewrite | ||
- | </ | ||
- | The setup of module mod_rewrite is done through so-called **rewrite rules**, which can be either defined directly in the server' | + | This option won't need any webserver |
- | <code apache> | + | To enable this option, select the '' |
- | RewriteEngine on | + | |
- | RewriteBase /dokuwiki | + | < |
- | + | $conf[' | |
- | RewriteRule ^_media/ | + | |
- | RewriteRule ^_detail/ | + | |
- | RewriteRule ^_export/ | + | |
- | RewriteRule ^$ doku.php | + | |
- | RewriteCond %{REQUEST_FILENAME} | + | |
- | RewriteCond %{REQUEST_FILENAME} | + | |
- | RewriteRule (.*) doku.php? | + | |
- | RewriteRule ^index.php$ | + | |
</ | </ | ||
- | |||
- | On the line '' | ||
- | |||
- | === Some Notes === | ||
- | |||
- | .htaccess files are only honored if Apache' | ||
- | |||
- | <code apache> | ||
- | < | ||
- | | ||
- | </ | ||
- | </ | ||
- | |||
- | PS: The above will '' | ||
- | |||
- | Alternatively you may simply specify the rewrite rules mentioned above directly in the httpd.conf: | ||
- | |||
- | <code apache> | ||
- | < | ||
- | RewriteEngine on | ||
- | ... rewrite rules here ... | ||
- | </ | ||
- | </ | ||
- | |||
- | You may have to restart Apache for these changes to work. | ||
- | |||
- | |||
- | Some users reported getting a "403 - Forbidden" | ||
- | |||
- | <code apache> | ||
- | Options +FollowSymlinks | ||
- | RewriteEngine on | ||
- | |||
- | ...etc. | ||
- | </ | ||
- | |||
- | The rewrite rules given above will map all non-existing files and directories to the DokuWiki main dispatcher, this may apply to virtual mappings (aliases). Some host sites map web access statistics to a virtual /stats directory. To be able to still access these virtual directories, | ||
- | |||
- | <code apache> | ||
- | ... | ||
- | RewriteCond %{REQUEST_FILENAME} | ||
- | RewriteCond %{REQUEST_FILENAME} | ||
- | RewriteCond %{REQUEST_URI} !^/ | ||
- | ... | ||
- | </ | ||
- | |||
- | If you're running without a RewriteBase, | ||
- | |||
- | <code apache> | ||
- | RewriteRule ^/ | ||
- | RewriteRule ^/ | ||
- | RewriteRule ^/ | ||
- | RewriteRule ^/$ %{DOCUMENT_ROOT}/ | ||
- | RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f | ||
- | RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d | ||
- | RewriteRule (.*) / | ||
- | </ | ||
- | |||
- | Each RewriteRule stanza must have a leading slash included, or Apache will return a 400 response code. | ||
- | |||
- | You may need to change | ||
- | If you have a **'' | ||
- | |||
- | <code apache> | ||
- | RewriteCond %{REQUEST_FILENAME} | ||
- | RewriteCond %{REQUEST_FILENAME} | ||
- | </ | ||
- | |||
- | If the URLs are still not rewriting correctly, double-check that this setting is actually set correctly. | ||
- | |||
- | == Apachectl status broken == | ||
- | |||
- | 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 | ||
- | |||
- | RewriteCond %{REQUEST_URI} !^/ | ||
- | |||
- | or creating an empty server-status file in dokuwiki root folder where doku.php is located. see forum post [[http:// | ||
- | ==== IIS ==== | ||
- | |||
- | === URL Rewrite Module for IIS 7 (Microsoft' | ||
- | |||
- | [[http:// | ||
- | |||
- | How to configure it for DokuWiki: | ||
- | |||
- | - Make sure you have the .htaccess file configured as described for Apache above | ||
- | - Install [[http:// | ||
- | - In IIS Manager, navigate to the site that hosts DokuWiki and double-click "URL Rewrite" | ||
- | - In the right pane (" | ||
- | - Select the .htaccess file and click Import | ||
- | - It may report an error that a RewriteBase rule is not supported. If you see this error, comment out the line in htaccess rewrite rules and run the import again | ||
- | - If the import succeeded, click Apply in the actions pane | ||
- | - In your DokuWiki configuration, | ||
- | |||
- | This procedure worked on my installation where DokuWiki was installed in the website root. It also works if Dokuwiki is installed in a subfolder. | ||
- | |||
- | === ISAPI Rewrite Lite == | ||
- | |||
- | IIS 6 and below don't come standard with a rewrite module. I used [[http:// | ||
- | |||
- | <code apache> | ||
- | # Dokuwiki rules | ||
- | # Fix RSS Feeds | ||
- | RewriteRule ^(/ | ||
- | RewriteRule ^(/ | ||
- | |||
- | RewriteRule ^(/ | ||
- | RewriteRule ^(/ | ||
- | RewriteRule ^(/ | ||
- | RewriteRule ^(/ | ||
- | |||
- | RewriteRule (/wiki/) $1doku.php [I,L] | ||
- | |||
- | RewriteRule ^(/ | ||
- | RewriteRule ^(/ | ||
- | RewriteRule ^(/ | ||
- | RewriteRule ^(/ | ||
- | RewriteRule ^(/ | ||
- | |||
- | # this rule fixes a problem to see the old revisions | ||
- | RewriteRule ^(/ | ||
- | |||
- | # Diff still broken unless none is selected under 'use nice URL' options. You can still enter and link to nice URLs but the DokuWiki program will use normal naming. | ||
- | </ | ||
- | |||
- | For all lines with '' | ||
- | |||
- | === Ionics Isapi Rewrite Filter === | ||
- | |||
- | It is also possible to use [[http:// | ||
- | |||
- | <code apache> | ||
- | IterationLimit 1 | ||
- | |||
- | RewriteRule ^/ | ||
- | RewriteRule ^/ | ||
- | RewriteRule ^/ | ||
- | RewriteRule ^/$ / | ||
- | # infinite redirect fix | ||
- | RewriteCond %{REQUEST_FILENAME} | ||
- | RewriteRule ^/ | ||
- | # end fix | ||
- | RewriteCond %{REQUEST_FILENAME} | ||
- | RewriteCond %{REQUEST_FILENAME} | ||
- | RewriteRule ^/ | ||
- | </ | ||
- | |||
- | ==== Lighttpd ==== | ||
- | |||
- | Assuming you have followed [[: | ||
- | |||
- | <code bash> | ||
- | |||
- | # We assume here that the wiki is accessible via http:// | ||
- | var.dokudir = "/ | ||
- | |||
- | # rewrites for dokuwiki | ||
- | $HTTP[" | ||
- | url.rewrite = ( | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | ) | ||
- | </ | ||
- | |||
- | Enable the rewrite module in lighttpd.conf by adding " | ||
- | ==== Nginx ==== | ||
- | |||
- | Nginx is a very fast and stable httpd, see more about [[http:// | ||
- | |||
- | For NGINX 0.7.65 or later ( [[http:// | ||
- | < | ||
- | server { | ||
- | server_name wiki.domain.tld; | ||
- | root / | ||
- | |||
- | location / { | ||
- | index doku.php; | ||
- | try_files $uri $uri/ @dokuwiki; | ||
- | } | ||
- | |||
- | location @dokuwiki { | ||
- | rewrite ^/ | ||
- | rewrite ^/ | ||
- | rewrite ^/ | ||
- | rewrite ^/(.*) / | ||
- | } | ||
- | |||
- | location ~ \.php$ { | ||
- | include fastcgi_params; | ||
- | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
- | fastcgi_pass unix:/ | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | For NGINX 0.6.x or later (tested up to 0.7.65) | ||
- | < | ||
- | server { | ||
- | | ||
- | | ||
- | |||
- | # | ||
- | | ||
- | | ||
- | |||
- | |||
- | | ||
- | | ||
- | |||
- | | ||
- | if (-f $request_filename) { | ||
- | break; | ||
- | } | ||
- | |||
- | if (!-f $request_filename) { | ||
- | #dokuwiki is installed in the root of the site | ||
- | rewrite ^/ | ||
- | rewrite ^/$ /doku.php last; | ||
- | break; | ||
- | | ||
- | } | ||
- | |||
- | # | ||
- | | ||
- | | ||
- | | ||
- | |||
- | | ||
- | fastcgi_pass | ||
- | fastcgi_param | ||
- | include | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | For nginx 0.7.27 or later (with try_files support) | ||
- | < | ||
- | 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 / | ||
- | index doku.php; | ||
- | |||
- | location / { try_files $uri $uri/ @dokuwiki; } | ||
- | |||
- | location @dokuwiki { | ||
- | rewrite ^/ | ||
- | rewrite ^/ | ||
- | rewrite ^/ | ||
- | rewrite ^/(.*) / | ||
- | } | ||
- | |||
- | 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: | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | For nginx 0.7.27 or later (with try_files support & dokuwiki is installed in the root of the site) | ||
- | |||
- | < | ||
- | listen | ||
- | root /var/www; | ||
- | server_name yourdomain.net; | ||
- | |||
- | location / { | ||
- | try_files $uri $uri/ @dk; | ||
- | rewrite ^/$ /doku.php last; | ||
- | } | ||
- | |||
- | location @dk { | ||
- | rewrite ^/(.*) / | ||
- | } | ||
- | |||
- | rewrite ^/ | ||
- | rewrite ^/ | ||
- | rewrite ^/ | ||
- | |||
- | include common.conf; | ||
- | } | ||
- | </ | ||
- | === Notes === | ||
- | |||
- | Nginx has complete support for fastcgi, please reference [[http:// | ||
- | |||
- | 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 like this: | ||
- | server { | ||
- | listen 443; | ||
- | ... | ||
- | location ~ .php$ { | ||
- | ... | ||
- | include fastcgi_params; | ||
- | ## sets $_SERVER[' | ||
- | 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/ | ||
- | |||
- | | $conf[' | ||
- | |||
- | 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> | ||
- | |||
- | Using Apache' | ||
- | |||
Line 423: | Line 63: | ||
This parameter is the PHP session ID and gets added by PHP automatically. It's completely unrelated to rewriting. To avoid it you can force PHP to always use cookies for sessions by setting the '' | This parameter is the PHP session ID and gets added by PHP automatically. It's completely unrelated to rewriting. To avoid it you can force PHP to always use cookies for sessions by setting the '' | ||
- | This is usually done in the php.ini config file (when using a web hoster check their support page if and how you can edit these values): | + | This is usually done in the php.ini config file: |
<code ini> | <code ini> | ||
Line 429: | Line 69: | ||
</ | </ | ||
- | If session id still work try: | + | You can also try: |
<code ini> | <code ini> | ||
session.use_trans_sid=0 | session.use_trans_sid=0 | ||
</ | </ | ||
- | When your PHP is used as Apache module you may be able to tweak these values using a .htaccess file using the following syntax: | + | ====== See Also ====== |
- | < | ||
- | php_flag session.use_only_cookies on | ||
- | php_flag session.use_trans_sid off | ||
- | </ | ||
- | |||
- | If you cannot use either of these solutions (many web hosts prevent editing php.ini and the use of php_flag in .htaccess), you will need to edit conf/ | ||
- | |||
- | <code php> | ||
- | ini_set(' | ||
- | </ | ||
- | |||
- | > My problem was that my **session.cookie_domain** was incorrectly set (I'm doing virtual hosting, and the domain name was incorrect). I added < | ||
- | |||
- | > In my case, FastCGI was causing session IDs to appear. Disabling it removed them. | ||
- | |||
- | ====== Also see ====== | ||
* [[: | * [[: | ||
+ | * [[https:// | ||
- | ====== Discussion ====== | ||
- | * I'm using an nginx setup with ispconfig3, where the rewrite directives are all done through an interface. I'm not sure if you can use even use the server block, but mine ended up looking like this (with wiki installed in domain.com/ | ||
- | location / | ||
- | index doku.php; | ||
- | try_files $uri $uri/ @namethisanything; | ||
- | } | ||
- | |||
- | location @namethisanything { | ||
- | rewrite ^/ | ||
- | rewrite ^/ | ||
- | rewrite ^/ | ||
- | rewrite ^/ | ||
- | }</ | ||
- | |||
- | * I'm using IIRF under IIS6 and the search box always redirected me back to /doku.php. I'm not sure if it's just my config, but the way I fixed it was to add the rule '' | ||
- | * Please note that it took me a few hours to figure out all by myself that I needed to add < | ||
- | * Even when using above configuration with Apache, often the URL becomes example.com/ | ||
- | * It's an implementation issue, not a rewriting problem. | ||
- | * Option = 2 works with IIS 6 (Windows 2003) and current nightly build if '' | ||
- | * For Option = 2, it seems that we need to specify the value of '' | ||
- | * For a long time I used DokuWiki (2) rewrite option, and now there are some links like '' | ||
- | * The solution was to add '' | ||
- | * Using rewrite rules for nginx that are presented breaks retrieval of images from dokuwiki. It seems to be not using the default value of root:< | ||
- | [error] 27613#0: *1 open() "/ | ||
- | location /wiki/lib/ { | ||
- | root / | ||
- | }</ | ||
- | * With IIS and Helicon Isapi_Rewrite, | ||
- | # Dokuwiki rules | ||
- | # Fix RSS Feeds | ||
- | RewriteRule ^(/ | ||
- | RewriteRule ^(/ | ||
- | |||
- | RewriteRule ^(/ | ||
- | RewriteRule ^(/ | ||
- | RewriteRule ^(/ | ||
- | RewriteRule ^(/ | ||
- | RewriteRule ^(/ | ||
- | |||
- | RewriteRule (/) $1doku.php [I,L] | ||
- | |||
- | RewriteRule ^(/ | ||
- | RewriteRule ^(/ | ||
- | RewriteRule ^(/ | ||
- | RewriteRule ^(/ | ||
- | RewriteRule ^(/)(.*) $1doku.php\? | ||
- | |||
- | # this rule fixes a problem to see the old revisions | ||
- | RewriteRule ^(/ | ||
- | |||
- | # Diff still broken unless none is selected under 'use nice URL' options. You can still enter and link to nice URLs but the DokuWiki program will use normal naming.</ | ||
- | |||
- | * I've put dokuwiki in its own subdirectory, | ||
- | *Try this tip: via php instead of htaccess, your example.com/ | ||
- | |||
- | * Apache methods works as advertised for LiteSpeed V6.2 |
rewrite.1398778645.txt.gz · Last modified: 2014-04-29 15:37 by 207.172.223.242