繁体   English   中英

.htaccess & 301:将大写字母 URL 重定向到相同的 URL 但小写

[英].htaccess & 301: Redirect URL with capital letters to same URL but in lowercase

1) 我得到了 mysite.com/about-me.php。

当我输入 mysite.com/About-me.php 时,我收到 404 错误。

I'd like to add some magic to my .htaccess so that mysite.com/My-PaGe.php (etc) redirects the user by 301, OR rewrites the URL (whatever is the best?) to mysite.com/my-page.php.
- 301还是重写最好?

2) 我是否可以添加一条适用于所有 URL 的规则,或者我是否必须手动指定所有不同的页面?

奖励 3) 如果有人知道如何将 mysite.com/mY-paGe.php 重写为 mysite.com/my-site,则额外奖励星

非常感谢

这会执行 301 重定向,所有带有大写字母的 url 都会被重写为小写版本:

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

另请参阅本文,特别是评论部分。 http://www.chrisabernethy.com/force-lower-case-urls-with-mod_rewrite/

可能需要在 httpd.conf 中指定这一行,并在 .htaccess 中指定 RewriteCond / RewriteRule

RewriteMap lc int:tolower

暂无
暂无

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

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