我使用RewriteEngine
以下htaccess
规则从 url中删除重音字母和大写字母:
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(A|Á|á|Â|â|Æ|æ|À|à|Å|å|Ã|ã|Ä|ä)(.*?)$
RewriteRule . %1a%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(B)(.*?)$
RewriteRule . %1b%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(C|Ç|ç)(.*?)$
RewriteRule . %1c%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(D)(.*?)$
RewriteRule . %1d%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(E|É|é|Ê|ê|È|è|Ð|ð|Ë|ë)(.*?)$
RewriteRule . %1e%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(F)(.*?)$
RewriteRule . %1f%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(G)(.*?)$
RewriteRule . %1g%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(H)(.*?)$
RewriteRule . %1h%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(I|Í|í|Î|î|Ì|ì|Ï|ï)(.*?)$
RewriteRule . %1i%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(J)(.*?)$
RewriteRule . %1j%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(K)(.*?)$
RewriteRule . %1k%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(L)(.*?)$
RewriteRule . %1l%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(M)(.*?)$
RewriteRule . %1m%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(N|Ñ|ñ)(.*?)$
RewriteRule . %1n%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(O|Ó|ó|Ô|ô|Œ|œ|Ò|ò|Ø|ø|Õ|õ|Ö|ö)(.*?)$
RewriteRule . %1o%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(P|ß|Þ|þ)(.*?)$
RewriteRule . %1p%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(Q)(.*?)$
RewriteRule . %1q%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(R)(.*?)$
RewriteRule . %1r%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(S)(.*?)$
RewriteRule . %1s3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(T)(.*?)$
RewriteRule . %1t%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(U|Ú|ú|Û|û|Ù|ù|Ü|ü)(.*?)$
RewriteRule . %1u%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(V)(.*?)$
RewriteRule . %1v%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(W)(.*?)$
RewriteRule . %1w%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(X)(.*?)$
RewriteRule . %1x%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(Y|Ý|ý|Ÿ|ÿ)(.*?)$
RewriteRule . %1y%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*?)(Z)(.*?)$
RewriteRule . %1z%3 [R=301,L]
如何使用RewriteMap
或mod_speling
按照本参考中的建议改进或缩短此代码:http ://www.askapache.com/htaccess/rewrite-uppercase-lowercase.html
更新答案
根据 Samurai8 的回答,我设置了一个环境变量,以便首先准备所有更改并在最后重定向。这是htaccess
另存为UTF-8
:
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(A|Á|á|Â|â|Æ|æ|À|à|Å|å|Ã|ã|Ä|ä)(.*)$ $1a$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(B)(.*)$ $1b$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(C|Ç|ç)(.*)$ $1c$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(C|Ç|ç)(.*)$ $1c$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(D)(.*)$ $1d$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(E|É|é|Ê|ê|È|è|Ð|ð|Ë|ë)(.*)$ $1e$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(F)(.*)$ $1f$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(G)(.*)$ $1g$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(H)(.*)$ $1h$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(I|Í|í|Î|î|Ì|ì|Ï|ï)(.*)$ $1i$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(J)(.*)$ $1j$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(K)(.*)$ $1k$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(L)(.*)$ $1l$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(M)(.*)$ $1m$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(N|Ñ|ñ)(.*)$ $1n$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(O|Ó|ó|Ô|ô|Œ|œ|Ò|ò|Ø|ø|Õ|õ|Ö|ö)(.*)$ $1o$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(P|ß|Þ|þ)(.*)$ $1p$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(Q)(.*)$ $1q$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(R)(.*)$ $1r$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(S)(.*)$ $1s$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(T)(.*)$ $1t$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(U|Ú|ú|Û|û|Ù|ù|Ü|ü)(.*)$ $1u$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(V)(.*)$ $1v$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(W)(.*)$ $1w$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(X)(.*)$ $1x$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(Y)(.*)$ $1y$3 [E=Redirect:1,N,R=301]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)(Z)(.*)$ $1z$3 [E=Redirect:1,N,R=301]
RewriteCond %{ENV:Redirect} =1
RewriteRule ^ - [R,L,E=!Redirect]
有用的参考资料