简体   繁体   English

将网址重写为全部小写

[英]rewriting URL to all lowercase

I have this rewrite rule in my .htaccess 我的.htaccess中有此重写规则

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/.]+)/?(.*)$ /$1.php/$2 [QSA,L]
RewriteRule ^api/([a-z]+)/([a-z]+) /api/$1_$2.php

How can I modify this to change everything in my URL to lowercase? 如何修改此设置以将URL中的所有内容更改为小写?

ie This: 即:

www.mysite.com/ThisURL/SHOULD/be_all_lowercse

Should be 应该

www.mysite.com/thisurl/should/be_all_lowercase

This article describes how to do it: 本文介绍了如何执行此操作:

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

Define a RewriteMap of type int (internal) referencing the tolower function, and call it where you want to do the lowercasing: 定义一个int类型(内部)的RewriteMap,引用tolower函数,并在您要进行小写的地方调用它:

RewriteMap  lc int:tolower
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/.]+)/?(.*)$ /${lc:$1}.php/${lc:$2} [QSA,L]
RewriteRule ^api/([a-z]+)/([a-z]+) /api/${lc:$1}_${lc:$2}.php}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM