Link to home
Start Free TrialLog in
Avatar of sharingsunshine
sharingsunshineFlag for United States of America

asked on

Need Help Making Destination Url Lower Case

Regex Destination url needs to be lower case.  I found this code that will convert it to lower case in the httpd.conf file.

RewriteMap lc int:tolower
RewriteRule (.*?[A-Z]+.*) ${lc:$1} [R]

Open in new window


Here is a sample url

http://www.theherbsplace.com/Garlic_Oil_Capsules_p_400.html

Open in new window

source url

https://www.theherbsplace.com/product/garlic_oil_capsules_p_400/

Open in new window

target url

I need to know if there is a better way to do this.  Because it seems very slow on Xampp.
Avatar of David S.
David S.
Flag of United States of America image

The alternative would be to use a PHP script. To handle the case conversion and the (external) redirect.

RewriteRule (.*?[A-Z]+.*) lowercase.php?page=%{REQUEST_URI}

Open in new window

I don't recall ever using RewriteMap myself.
Avatar of sharingsunshine

ASKER

I found this one

<?php
if(isset($_GET['rewrite-strtolower-url'])) {
    $url = $_GET['rewrite-strtolower-url'];
    unset($_GET['rewrite-strtolower-url']);
    $params = http_build_query($_GET);
    if(strlen($params)) {
        $params = '?' . $params;
    }
    // if you don't have SSL/a security certificate at the destination change https:// to http:// below
    header('Location: https://' . $_SERVER['HTTP_HOST'] . '/' . strtolower($url) . $params, true, 301);
    exit;
}
header("HTTP/1.0 404 Not Found");
die('Unable to convert the URL to lowercase. You must supply a URL to work upon.');

Open in new window


but I couldn't make it work.  Do you have any suggestions?
ASKER CERTIFIED SOLUTION
Avatar of shobinsun
shobinsun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did you change the RewriteRule to use "rewrite-strtolower-url" instead of "page"?
yes, I did and I got it to work but it is very slow.  I tried the other script and it is 10X faster.
Thanks for the help.