0

I have a very simple redirect in PHP that redirects to lowercase, I cannot do this in .htaccess because of my shared server limitations.

        if (preg_match('/[A-Z]+/', $url)){
        header("HTTP/1.1 301 Moved Permanently"); 
        header("Location: ".strtolower($url));
        exit;       
    }

However there are certain cases where the .htaccess may have already redirected a url. All these cases have urlencoded chars ie. %7E.

So I need to check for any uppercase characters that aren't in the form of a urlencoded char and replace them with lowercase characters.

Worst (or perhaps best) case I don't want to attempt an already redirected header can I check to see if it's already been redirected in PHP.

Any ideas on how I could go about this please?

4

1 回答 1

0

您只需解码 url 以删除 urlencoded 字符,然后使用 strtolower(),然后将其编码回来:

header("Location: ". urlencode(strtolower(urldecode($url))));
于 2013-04-12T22:43:57.087 回答