开发者

How to convert text to lowercase URLs using .htaccess

开发者 https://www.devze.com 2023-02-28 07:11 出处:网络
I want to set up 301 redirects in my .htaccess file so URLs like http://example.com/Foo http://example.com/Foo/Bar

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
0

精彩评论

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