问题描述
如何在 Apache 上修改我的 .htaccess 文件以执行以下操作:
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(营销材料),我需要确保这些 URL 仍然有效;Windows 网络服务器不区分大小写,但 Linux 网络服务器是.
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 更改为小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!