使用Apache htaccess文件更改URL为小写 [英] Using Apache htaccess file to change URL to lowercase
问题描述
如何修改我的.htaccess文件在Apache做到以下几点:
How can I modify my .htaccess file on Apache to do the following:
如果URL中的.aspx结束,重写整个URL为小写。
"If the URL ends in .aspx, rewrite the entire URL to lowercase."
背景故事:我最近迁移从ASPX托管到Linux / Apache的托管网站。有一些旧网址在野外(营销材料),我需要确保这些URL仍然有效;的Windows Web服务器不区分大小写,但Linux Web服务器的。
Backstory: I recently migrated a website from ASPX hosting to Linux/Apache hosting. There are some old URLs in the wild (marketing materials), and I need to make sure that those URLs still work; Windows web servers are not case-sensitive but Linux web servers are.
先谢谢了。
推荐答案
您需要定义的改写地图只能在服务器/虚拟主机配置文件来完成,而不是在htaccess的文件。你需要添加类似:
You need to define a rewrite map which can only be done in server/vhost config files, not in htaccess files. You'll need to add something like:
RewriteMap lc int:tolower
然后在你的htaccess文件,你可以创建这样一个规则:
Then in your htaccess file, you can create a rule like:
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule ^(.*\.aspx)$ ${lc:$1} [L,NC]
这将检查是否有在URI大写字母,然后应用这一切都变成小写字母映射。
This will check that there are capital letters in the URI, then apply the map which turns everything into lowercase letters.
这篇关于使用Apache htaccess文件更改URL为小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!