Force lowercase .htaccess

回眸只為那壹抹淺笑 提交于 2020-01-15 03:44:10

问题


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

回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/6736931/force-lowercase-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!