How to convert text to lowercase URLs using .htaccess

北战南征 提交于 2019-12-31 04:04:06

问题


I want to set up 301 redirects in my .htaccess file so URLs like

http://example.com/Foo

http://example.com/Foo/Bar

http://example.com/Foo/Bar/Blah

change to

http://example.com/products/foo

http://example.com/products/foo/bar

http://example.com/products/foo/bar/blah

There are a discrete number of "Foo" cases which I can target with RewriteRule ^Foo, but how to append the "products" part?


回答1:


First add this line in <VirtualHost> section OR at the end of your httpd.conf file:

RewriteMap lc int:tolower

Then have these rules in .htaccess file:

RewriteEngine on
Options +FollowSymlinks -MultiViews  
RewriteRule ^(Foo.*)$ /products/${lc:$1} [R=301,L]
  • R=301 for sending back 301 to browser
  • L for marking it last rule


来源:https://stackoverflow.com/questions/5740022/how-to-convert-text-to-lowercase-urls-using-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!