This module tries to imitate the famous apache module. However not all
features supported in the original one can be used with this version.
See bottom of this file for what it doesn't understand.
mod_rewrite is used to map requested file names to existing files by using
regular expressions. For example, if your browser wants to GET say
http://www.example.com/thisfile.html
you can use the keyword "RewriteRule" to change the requested filename:
RewriteRule thisfile changedfilenameso that a file named "changedfilename.html" gets sent back to the browser.
Such keywords must be written into files named ".htaccess" in the directory the rewriting shall take place.
This mod_rewrite supports most of the regular expression syntax that you
can use with apache's module:
. matches any character .+ matches many of any character, at a minimum of 1 .* matches also zero length character string [a-z] matches one character out of specified range [4x#] matches one of the specified characters () grouping (and for backreferences in replacement string) (a|bc) matches "a" or "bc" .{2,5} exactly specified repeat count (here: 2 to 5 of any character)
RewriteRule file([a-z])+[.]html new$1.phpwould rewrite specified name "fileABC.html" to "newABC.php", where the dot occurred in square brackets to only match the dot and not _any_ character.
RewriteRules may also have some flags specified (write these in brackets!, comma separated list of flags), so the complete Syntax is:
RewriteRule REGEX REPLACEMENT [flag1,flag2,...]
There exists another keyword, which just does regex matches, but no rewritings; and by failure prevents following RewriteRules from being executed:
RewriteCond TESTSTRING CONDPATTERN [NOCASE,ORnext]
Here the second argument is the regular expression, and NC and OR are the
only allowed flags.
TESTSTRING can be constructed by using %{SERVER_VARS} or backreferences
to last RewriteRule-groups $NN or RewriteCond-groups %NN.
For more Information see the documentation of apache's mod_rewrite.
Available vars are for now:
CONDPATTERN may be a regular expression as seen above, or:
will reflect changes to the requested path name in server error
responses, when for example the rewritten file name does not
exist or has no read permissions set; otherwise the url from the
request will be printed in such server messages.
Note: This config directive affects mod_multiviews as well.
RewriteRule ^(index.html)*$ otherpath/new-index.html
this mod_rewrite does not support:
- some of that very special Rule-flags#-- WAP-redirect, based upon accepted file type RewriteCond %{HTTP_ACCEPT} (x-)*(application|text)/(x-)*(vnd[-.])*(wap[-.]|wml)+ RewriteRule ^(index.html)*$ index.wml [L] #-- redirect file names to google search RewriteRule ^(.+)$ http://www.google.de/search?q=$1 [R=seeother]