2

I tried to do

RewriteEngine On
RewriteMap  lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]

But, I receive a 500 internal error. Not sure what's wrong.

Error:

/home/public_html/.htaccess: RewriteMap not allowed here
[Mon Jul 18 10:33:06 2011] [alert] [client *.*.*.*] /home/public_html/.htaccess: RewriteMap not allowed here
hakre
  • 193,403
  • 52
  • 435
  • 836
Digii
  • 21
  • 2
  • `/home/public_html/.htaccess: RewriteMap not allowed here [Mon Jul 18 10:33:06 2011] [alert] [client *.*.*.*] /home/public_html/.htaccess: RewriteMap not allowed here ` <= is the error it throws – Digii Jul 18 '11 at 17:42
  • See [this question](http://stackoverflow.com/q/3306070/206403). – gen_Eric Jul 18 '11 at 17:45
  • For those coming from google, what you really want is a [canonical meta tag](https://moz.com/learn/seo/canonicalization). – Giovanni Jul 16 '15 at 12:17

2 Answers2

3

RewriteMap CANNOT be declared in .htaccess file -- only in server config / virtual hosting context: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritemap

If you cannot edit Apache's config files, then you are out of luck -- you have to implement such redirect using some script -- PHP, for example.

LazyOne
  • 158,824
  • 45
  • 388
  • 391
3

If your using PHP you could put this in the beginning of your index.php

$url = $_SERVER['REQUEST_URI'];
$pattern = '/([A-Z]+)/';

if(preg_match($pattern, $url)) {
    $new_url = strtolower($url);

    Header( 'HTTP/1.1 301 Moved Permanently' );
    Header( 'Location: ' . $new_url );
    exit;
}

// your code here
Esben
  • 1,943
  • 1
  • 18
  • 37
  • 1
    This will lowercase also the querystring, which can lead to problems. If for some reason you really have to do this, split the path and the querystring with the parse_url function and lowercase only the path. – Giovanni Jul 16 '15 at 12:11