强制网址小写 - 覆盖previous规则 [英] Force lower case of URLs - Override previous rules

查看:180
本文介绍了强制网址小写 - 覆盖previous规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一个充满previous规则相当可怕寻找.htaccess文件。我所要做的仅仅是让每一个URL小写的搜索引擎优化的原因。目前,谷歌网站管理员抱怨重复的网页。例如:www.example.com/AbC1.php具有相同的内容www.example.com/abc1.php。为了解决这个问题,我把下面几行到我vhosts.conf

I have inherited a rather scary looking .htaccess file that is filled with previous rules. What I am trying to do is simply make every single URL lowercase for SEO reasons. Currently Google Webmasters is complaining about duplicate pages. eg: www.example.com/AbC1.php has the same content as www.example.com/abc1.php. To solve this I placed the following lines into my vhosts.conf

#Make URL's lower case
RewriteEngine On
RewriteMap lowercase int:tolower
RewriteCond \$1 [A-Z]
RewriteRule ^/(.*)$ /\${lowercase:\$1} [R=301,L]

但由于之一的许多规则,我在我的.htaccess文件这个规则是行不通的。我可以添加上述规则,并确保其覆盖任何其他规则?

But due to one of the many rules I have in my .htaccess file this rule isn't working. Can I add that above rule and ensure that it overrides any other rules?

推荐答案

您可以在上面的任何其他规则添加在你的htaccess的文件,但重写地图定义必须是在你的虚拟主机的配置,所以在虚拟主机:

You can add it above any other rules in your htaccess file but the rewrite map definition must be in your vhost config, so in vhost:

RewriteEngine On
RewriteMap lowercase int:tolower

而在你的htaccess文件的顶部:

And in the very top of your htaccess file:

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

(请注意,你并不需要斜线)

(note that you don't need to leading slash)

这篇关于强制网址小写 - 覆盖previous规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆