简体   繁体   English

将大写 url 重写为小写 url htaccess

[英]rewrite uppercase url to lowercase url htaccess

I want my urls that contain uppercase characters to be redirected to lowercase url's.我希望将包含大写字符的 url 重定向到小写 url。 Unfortunatly i don't have access to the httpd.config file.不幸的是,我无权访问 httpd.config 文件。 So i tried this method to rewrite the urls with the htaccess file: http://www.askapache.com/htaccess/rewrite-uppercase-lowercase.html .所以我尝试用这种方法用 htaccess 文件重写 url: http : //www.askapache.com/htaccess/rewrite-uppercase-lowercase.html But it adds extra / because it's a loop and also it doesn't work (504 error) when the url consists of more than two parts (ex www.mysite.com/part1/part2/part3/ )但它增加了额外的 / 因为它是一个循环并且当 url 由两个以上的部分组成时它也不起作用(504 错误)(例如 www.mysite.com/part1/part2/part3/ )

How can i fix this or is there an other/better method?我该如何解决这个问题,或者有其他/更好的方法吗?

If you look at your Apache error log (which is most likely huge thanks to this thing), you should see something along the lines of:如果你查看你的 Apache 错误日志(这很可能是因为这个事情),你应该看到一些类似的东西:

[Sun Dec 08 09:46:28.884713 2013] [rewrite:trace3] [pid 4860:tid 1532] mod_rewrite.c(468): [client ::1:50143] ::1 - - [localhost/sid#56cb48][rid#1642140/initial] [perdir C:/wamp/www/] strip per-dir prefix: C:/wamp/www/AAA/AA -> AAA/AA
[Sun Dec 08 09:46:28.884713 2013] [rewrite:trace3] [pid 4860:tid 1532] mod_rewrite.c(468): [client ::1:50143] ::1 - - [localhost/sid#56cb48][rid#1642140/initial] [perdir C:/wamp/www/] applying pattern '[A-Z]' to uri 'AAA/AA'
[Sun Dec 08 09:46:28.884713 2013] [rewrite:trace5] [pid 4860:tid 1532] mod_rewrite.c(468): [client ::1:50143] ::1 - - [localhost/sid#56cb48][rid#1642140/initial] setting env variable 'HASCAPS' to 'TRUE'
[Sun Dec 08 09:46:28.884713 2013] [rewrite:trace3] [pid 4860:tid 1532] mod_rewrite.c(468): [client ::1:50143] ::1 - - [localhost/sid#56cb48][rid#1642140/initial] [perdir C:/wamp/www/] add path info postfix: C:/wamp/www/AAA -> C:/wamp/www/AAA/AA
[Sun Dec 08 09:46:28.885713 2013] [rewrite:trace3] [pid 4860:tid 1532] mod_rewrite.c(468): [client ::1:50143] ::1 - - [localhost/sid#56cb48][rid#1642140/initial] [perdir C:/wamp/www/] strip per-dir prefix: C:/wamp/www/AAA/AA -> AAA/AA
[Sun Dec 08 09:46:28.885713 2013] [rewrite:trace3] [pid 4860:tid 1532] mod_rewrite.c(468): [client ::1:50143] ::1 - - [localhost/sid#56cb48][rid#1642140/initial] [perdir C:/wamp/www/] applying pattern '^([^A]*)A(.*)$' to uri 'AAA/AA'
[Sun Dec 08 09:46:28.885713 2013] [rewrite:trace2] [pid 4860:tid 1532] mod_rewrite.c(468): [client ::1:50143] ::1 - - [localhost/sid#56cb48][rid#1642140/initial] [perdir C:/wamp/www/] rewrite 'AAA/AA' -> 'aAA/AA'
[Sun Dec 08 09:46:28.885713 2013] [rewrite:trace3] [pid 4860:tid 1532] mod_rewrite.c(468): [client ::1:50143] ::1 - - [localhost/sid#56cb48][rid#1642140/initial] [perdir C:/wamp/www/] add per-dir prefix: aAA/AA -> C:/wamp/www/aAA/AA
[Sun Dec 08 09:46:28.885713 2013] [rewrite:trace3] [pid 4860:tid 1532] mod_rewrite.c(468): [client ::1:50143] ::1 - - [localhost/sid#56cb48][rid#1642140/initial] [perdir C:/wamp/www/] add path info postfix: C:/wamp/www/aAA/AA -> C:/wamp/www/aAA/AA/AA

Everything goes well, until the path info postfix is applied.一切顺利,直到应用了路径信息后缀。 I am not sure why that is, but I know that applying the DPI flag to the 26 RewriteRules that transform uppercase to lowercase will most likely solve your issue.我不确定为什么会这样,但我知道将DPI标志应用于将大写字母转换为小写字母的 26 个 RewriteRules 很可能会解决您的问题。

# If there are caps, set HASCAPS to true and skip next rule
RewriteRule [A-Z] - [E=HASCAPS:TRUE,S=1]

# Skip this entire section if no uppercase letters in requested URL
RewriteRule ![A-Z] - [S=28]

# Replace single occurance of CAP with cap, then process next Rule.
RewriteRule ^([^A]*)A(.*)$ $1a$2 [DPI]
RewriteRule ^([^B]*)B(.*)$ $1b$2 [DPI]
RewriteRule ^([^C]*)C(.*)$ $1c$2 [DPI]
RewriteRule ^([^D]*)D(.*)$ $1d$2 [DPI]
RewriteRule ^([^E]*)E(.*)$ $1e$2 [DPI]
RewriteRule ^([^F]*)F(.*)$ $1f$2 [DPI]
RewriteRule ^([^G]*)G(.*)$ $1g$2 [DPI]
RewriteRule ^([^H]*)H(.*)$ $1h$2 [DPI]
RewriteRule ^([^I]*)I(.*)$ $1i$2 [DPI]
RewriteRule ^([^J]*)J(.*)$ $1j$2 [DPI]
RewriteRule ^([^K]*)K(.*)$ $1k$2 [DPI]
RewriteRule ^([^L]*)L(.*)$ $1l$2 [DPI]
RewriteRule ^([^M]*)M(.*)$ $1m$2 [DPI]
RewriteRule ^([^N]*)N(.*)$ $1n$2 [DPI]
RewriteRule ^([^O]*)O(.*)$ $1o$2 [DPI]
RewriteRule ^([^P]*)P(.*)$ $1p$2 [DPI]
RewriteRule ^([^Q]*)Q(.*)$ $1q$2 [DPI]
RewriteRule ^([^R]*)R(.*)$ $1r$2 [DPI]
RewriteRule ^([^S]*)S(.*)$ $1s$2 [DPI]
RewriteRule ^([^T]*)T(.*)$ $1t$2 [DPI]
RewriteRule ^([^U]*)U(.*)$ $1u$2 [DPI]
RewriteRule ^([^V]*)V(.*)$ $1v$2 [DPI]
RewriteRule ^([^W]*)W(.*)$ $1w$2 [DPI]
RewriteRule ^([^X]*)X(.*)$ $1x$2 [DPI]
RewriteRule ^([^Y]*)Y(.*)$ $1y$2 [DPI]
RewriteRule ^([^Z]*)Z(.*)$ $1z$2 [DPI]

# If there are any uppercase letters, restart at very first RewriteRule in file.
RewriteRule [A-Z] - [N]

RewriteCond %{ENV:HASCAPS} TRUE
RewriteRule ^/?(.*) /$1 [R,L]

More information about the DPI flag can be found here and the general documentation of mod_rewrite can be found here .关于DPI标志的更多信息可以在这里找到,mod_rewrite 的一般文档可以在这里找到。

at VirtualHosts site Directory (sites enabled)在 VirtualHosts 站点目录(启用站点)

RewriteEngine On
RewriteMap lowercase int:tolower 

and at .htaccess:并在 .htaccess:

RewriteCond $1 [A-Z]
RewriteRule ^(.*)$ /${lowercase:$1} [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM