I took the re-write rules posted here by astehlik w/o a grain of salt a few months ago and never looked back. However, since they appear to break down as of 4.5.1 I’ve been forced to look again and this time look much closer. This revealed some flaws and/or discrepancies in the rules relative to those used for Apache. For example, query strings in URIs get dropped (applies to all versions) and pics will not generate (as of 4.5.1).
Below I’ve rewritten the rewrite rules (ha ha) to more closely match the original Apache rules. The only thing I could not reproduce accurately was Apache’s ability to re-direct conditionally against file existence. I’ve mentioned the work-around for this in the comments below. Haven’t run these tests on a production server yet (but will soon) so use at your own risk, and check if you have to repair line breaks if you copy from this post.
FOR 4.5.1 AND ABOVE:
If the shop runs in a subdirectory, set this to /yourdirectory/
var.oxidpath = "/"
var.accessiblefiles = “.html|.jpg|.css|.pdf|.doc|.gif|.png|.js|.htc”
Block TRACE|TRACK http request methods
$HTTP[“request-method”] =~ “^(TRACE|TRACK)” {
url.access-deny = ( “” )
}
Make the mod_rewrite system requirements check work and stop further rewrites
url.rewrite-once = (
"^" + oxidpath + “.*oxseo.php?mod_rewrite_module_is=off$” => oxidpath + “oxseo.php?mod_rewrite_module_is=on”,
)
If actual file does not exist AND not accessing an internal directory AND not an accessible
file AND not already eligible for seo processing (ends with / or .html) then assume that uri
is seo eligible but missing trailing slash. Add slash and redirect (permanently).
url.rewrite-if-not-file = (
# Add missing slash then use $0 to stop further processing and go directly to redirect rule.
"^("+oxidpath+"(?!admin|core|export|modules|out|setup|tmp|views)[^?]*)((?<!/|.html)\?.*)?(?<!/|"+accessiblefiles+")$" => "$0",
)
1. If actual file does not exist AND not accessing an internal directory AND and uri is eligible
for seo processing (ends with / or .html), then send request to oxseo.php.
2. Send non-existing images to image generator script.
url.rewrite-repeat-if-not-file = (
# Request meets requirements for oxseo.php AND has a trailing slash
"^("+oxidpath+"(?!admin|core|export|modules|out|setup|tmp|views)[^?]*(?:/|.html))((?<=/|.html)\?.*)?$" => oxidpath+"oxseo.php$2",
# Run php script to generate pics not yet generated
"^(" + oxidpath + "out/pictures/" + ".*(\.jpg|\.gif|\.png)" + ")$" => oxidpath + "core/utils/getimg.php",
)
If trailing slash is missing from a oxseo.php eligible path, add it and redirect permanently.
IMPORTANT NOTE/WORK-AROUND:
This rule can’t be made conditional upon file existance, like with Apache, so will catch undesired requests such as to
existing php files. For example, without the file exists check, this rule will erroneously add a trailing slash to a
oxseo.php request, as well as any other .php request, and break seo functionality. As a work-around, modifying rule
to ignore all php requests. This should cover existing files accessed by site since all other relavent extensions are
already ignored.
Note: A $PHYSICAL[“existing-path”] field will be added to Lighty 1.5 that could fix this.
url.redirect-code = 301
$HTTP[“host”] =~ “(.)" {
url.redirect = (
# Original rule:
#"^("+oxidpath+"(?!admin|core|export|modules|out|setup|tmp|views)[^?])((?<!/|.html)?.)?(?<!/|"+accessiblefiles+")$" => “http://%1$1/$2”,
# Work-around rule:
"^("+oxidpath+"(?!admin|core|export|modules|out|setup|tmp|views)[^?])((?<!/|.html|.php)?.*)?(?<!/|”+accessiblefiles+"|.php)$" => “http://%1$1/$2”,
)
}
FOR 4.5.0 AND LESS:
Replace the url.rewrite-repeat-if-not-file rule as follows.
If actual file does not exist AND not accessing an internal directory AND and uri is eligible
for seo processing (ends with / or .html), then send request to oxseo.php.
url.rewrite-repeat-if-not-file = (
# Request meets requirements for oxseo.php AND has a trailing slash
"^("+oxidpath+"(?!admin|core|export|modules|out|setup|tmp|views)[^?](?:/|.html))((?<=/|.html)?.)?$" => oxidpath+“oxseo.php$2”,
)