简体   繁体   English

htaccess 大写 URL 转小写

[英]htaccess Uppercase URL to lowercase

On a website there is folder products/ and inside are php files with some Uppercase characters.在网站上有文件夹products/ ,里面是带有一些大写字符的 php 文件。

Example: www.example.com/products/BIT-Defendar.php示例: www.example.com/products/BIT-Defendar.php

Now this urls exist for years and all around search engines.现在这个 urls 已经存在多年并且遍布搜索引擎。 It was a mistake from the product manager.这是产品经理的失误。

But I want to fix this i want only lowercase URL's.但我想解决这个问题,我只想要小写的 URL。

Will this fix my issue?这会解决我的问题吗? CheckSpelling On CheckCaseOnly On (1) CheckSpelling On CheckCaseOnly On (1)

And whats different with mentioned above and: (2)和上面提到的有什么不同(2)

RewriteMap tolowercase int:tolower 
RewriteRule ^(.*)$ ${tolowercase:$1}

If I use (1) then all works wither I request url lower cased or upper-cased (but will I have search engine problems?)如果我使用(1)那么所有的工作都会随着我请求 url 小写或大写(但我会遇到搜索引擎问题吗?)

If I use (2) I have to rename all files inside of products/ folder to lowercase.如果我使用(2),我必须将products/文件夹内的所有文件重命名为小写。

---- EDIT ---- - - 编辑 - -

When i use RewriteRule i get transferred to domain root if url is uppercase, if i use CheckSpelling and CheckCaseOnly then all fine.当我使用RewriteRule ,如果 url 是大写,我会被转移到域根目录,如果我使用CheckSpellingCheckCaseOnly那么一切都很好。

I have tested with this and i get:我已经这个测试,我得到:

RewriteCond %{REQUEST_URI} [A-Z]    

- This condition was met - 满足这个条件

RewriteRule (.*) ${tolowercase:$1} [R=301,L]    

- This rule was met, the new url is http://www.example.com/ ${tolowercase:products/BIT-Defendar.php} - 符合此规则,新网址为http://www.example.com/ ${tolowercase:products/BIT-Defendar.php}

- Test are stopped, because of the R in your RewriteRule options. - 由于 RewriteRule 选项中的 R,测试已停止。 A redirect will be made with status code 301将使用状态代码 301 进行重定向

My setup in httpd.conf :我在httpd.conf设置:

<VirtualHost *:80>
 RewriteMap tolowercase int:tolower
</VirtualHost>

Using the CheckSpelling and/or CheckCaseOnly directive may cause undesired results, as mentioned at the bottom here :使用CheckSpelling和/或CheckCaseOnly指令可能导致意外的结果,因为在底部所提及的在这里

1, performance issues
2, some files might be skipped
3, some files might be misinterpreted

I would think it unwise to allow apache make the corrections for you, as you rely on apache to search directories and files for every single look up, whereas with the lowercase map, it puts you in full control and just creates strict standards.我认为允许 apache 为您进行更正是不明智的,因为您依赖 apache 为每次查找搜索目录和文件,而使用小写映射,它让您完全控制并且只是创建严格的标准。

I would recommend adding a flag [R=301] which will inform search engines that this is the new file, and you won't have any search engine related issues:我建议添加一个标志[R=301] ,它会通知搜索引擎这是新文件,并且您不会遇到任何与搜索引擎相关的问题:

RewriteMap tolowercase int:tolower 
RewriteRule ^(.*)$ ${tolowercase:$1} [R=301,L]

You would have to rename your files, as they will no longer be recognized, but you can write a simple script to scan all files, and rename them as lowercase.您必须重命名文件,因为它们将不再被识别,但您可以编写一个简单的脚本来扫描所有文件,并将它们重命名为小写。

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

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