How to convert text to lowercase URLs using .htaccess
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 d开发者_StackOverflowiscrete number of "Foo" cases which I can target with RewriteRule ^Foo, but how to append the "products" part?
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
精彩评论