开发者

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

1) I got mysite.com/about-me.php.

When I type in mysite.com/About-me.php I get a 404 error.

I'd like to add some开发者_JAVA技巧 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.

- Is 301 or rewrite the best?

2) Is is possibly for me to add one rule that applies to all URL's, or do I have to manually specify all different pages?

Bonus 3) Extra bonus star if anybody knows how to rewrite mysite.com/mY-paGe.php to mysite.com/my-site

Thanks alot


This does a 301 redirect, all urls that have an uppercase letter get rewritten to a lowercase version:

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

See also this article, in particular the comments section. http://www.chrisabernethy.com/force-lower-case-urls-with-mod_rewrite/

You may need to specify this line in httpd.conf, and the RewriteCond / RewriteRule in .htaccess

RewriteMap lc int:tolower
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜