开发者

Quickest way to rewrite urls to lowercase?

开发者 https://www.devze.com 2023-01-20 02:33 出处:网络
I\'m looking f开发者_StackOverflow中文版or a way, preferably with .htaccess to rewrite a url when a user types in something with a capital.

I'm looking f开发者_StackOverflow中文版or a way, preferably with .htaccess to rewrite a url when a user types in something with a capital.

For example, the url could be website.com/pagename

and the usertypes in website.com/PageName or website.com/PAGENAME

Whats the best way to do with without slowing down page load?


You can either do an HTTP redirect (via Apache):

RewriteEngine on
RewriteMap lowercase int:tolower
RewriteCond $1 [A-Z]
RewriteRule ^/(.*)$ /${lowercase:$1} [R=301,L]

or do the processing in PHP:

$_SERVER['REQUEST_URI']=strtolower($_SERVER['REQUEST_URI']);

HTTP redirection isn't really as efficient as the PHP solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消