Convert to lowercase in a mod_rewrite rule

前端 未结 3 1617
梦如初夏
梦如初夏 2020-11-29 10:18

I would like URLs like server.com/foo to be case-insensitive. But server.com/foo actually gets mod_rewrite\'d to server.com/somedir/foo

(Assume that all the files in

相关标签:
3条回答
  • 2020-11-29 10:50
    RewriteMap tolower int:tolower
    RewriteRule  ^([^/]+)/?$  somedir/${tolower:$1}
    
    0 讨论(0)
  • 2020-11-29 10:53

    I would make it a 301 redirect, NOT a URL rewrite, for SEO purposes:

    RewriteMap tolower int:tolower
    RewriteRule  ^([^/]+)/?$  somedir/${tolower:$1} [R=301,L]
    
    0 讨论(0)
  • 2020-11-29 11:00

    First, put the following line in the <VirtualHost> section of your .conf file. (For me that lives at /etc/httpd/vhosts.d/00foo.conf.)

    RewriteMap lc int:tolower 
    

    You can replace lc with any name you want. Then restart apache, which you can do with sudo service httpd restart.

    Finally, add this in your .htaccess file:

    RewriteRule ^/(.*)$ /${lc:$1} 
    
    0 讨论(0)
提交回复
热议问题