Forum Moderators: phranque
I have tried searching for examples and even looked at learning regex but it appears daunting and more complex than the single file redirects I done before.
Using .htaccess limits the possibilities, since RewriteMap -- only available in a server config context -- might be a better solution.
However, two resources come to mind:
First, you might want to investigate Apache mod_speling [httpd.apache.org] to correct upper/lowercase issues.
Secondly, take a look at the RewriteRule [N] (Next) flag, which provides for re-running your RewriteRules if a match is found.
Although it's inefficient overall, I'd propose using a rule that replaces a single underscore with a hyphen, ending with an [N] flag. This will iteratively replace all hyphens. Put this code as lose as possible to the beginning of your Rules, because all of them will be re-processed for each underscore replaced.
On the last iteration, no underscore will be found, so the Rule will fall through. Follow this with a directive to enable mod_speling. mod_speling will then correct the case of the rewritten URI.
The above approach is untested, and (I believe) horribly inefficient. But if there are not other choices, such as using a script to process the URI, it might work.
HTH,
Jim
so far I've got to
<?php
$str = $_SERVER['PHP_SELF'];
$str = strtolower($str);
$newstr = strtr($str, "_", "-");
if ($newstr==$str) {
header('Location: "error-404.pl');
} else {
header('Location: $newstr');
}
?>
but wonder before I go too far if there is disadvantage using php rather than Mod's? Would it be much slower to do this?
Thanks for the replys so far..