我们刚从IIS服务器迁移到Apache,我们正试图让我们的链接与Apache的区分大小写一致。我们有很多页面,所以我要逐个目录进行更改。我先测试它以确保它有效。我正在添加.htaccess
文件以将传入的网址转换为小写。我正在使用以下内容,因为我不想搞乱httpd.config:
RewriteEngine On
RewriteBase /advertising/
# 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
RewriteRule ^([^B]*)B(.*)$ $1b$2
RewriteRule ^([^C]*)C(.*)$ $1c$2
RewriteRule ^([^D]*)D(.*)$ $1d$2
RewriteRule ^([^E]*)E(.*)$ $1e$2
RewriteRule ^([^F]*)F(.*)$ $1f$2
RewriteRule ^([^G]*)G(.*)$ $1g$2
RewriteRule ^([^H]*)H(.*)$ $1h$2
RewriteRule ^([^I]*)I(.*)$ $1i$2
RewriteRule ^([^J]*)J(.*)$ $1j$2
RewriteRule ^([^K]*)K(.*)$ $1k$2
RewriteRule ^([^L]*)L(.*)$ $1l$2
RewriteRule ^([^M]*)M(.*)$ $1m$2
RewriteRule ^([^N]*)N(.*)$ $1n$2
RewriteRule ^([^O]*)O(.*)$ $1o$2
RewriteRule ^([^P]*)P(.*)$ $1p$2
RewriteRule ^([^Q]*)Q(.*)$ $1q$2
RewriteRule ^([^R]*)R(.*)$ $1r$2
RewriteRule ^([^S]*)S(.*)$ $1s$2
RewriteRule ^([^T]*)T(.*)$ $1t$2
RewriteRule ^([^U]*)U(.*)$ $1u$2
RewriteRule ^([^V]*)V(.*)$ $1v$2
RewriteRule ^([^W]*)W(.*)$ $1w$2
RewriteRule ^([^X]*)X(.*)$ $1x$2
RewriteRule ^([^Y]*)Y(.*)$ $1y$2
RewriteRule ^([^Z]*)Z(.*)$ $1z$2
# If there are any uppercase letters, restart at very first RewriteRule in file.
RewriteRule [A-Z] - [N]
RewriteCond %{ENV:HASCAPS} TRUE
RewriteRule ^/?(.*) /$1 [R=301,L]
正如您所看到的,我正在advertising
目录中对此进行测试,但它会将链接重定向到根文件夹。我清除了缓存并再次检查,甚至使用另一台计算机进行测试。网址仍然转换为根目录。我做错了什么?
答案 0 :(得分:0)
确保在上次重定向中使用相对URI,即
RewriteEngine On
RewriteBase /bible/
# Replace single occurance of CAP with cap, then process next Rule.
RewriteRule ^([^A]*)A(.*)$ $1a$2 [L]
RewriteRule ^([^B]*)B(.*)$ $1b$2 [L]
RewriteRule ^([^C]*)C(.*)$ $1c$2 [L]
RewriteRule ^([^D]*)D(.*)$ $1d$2 [L]
RewriteRule ^([^E]*)E(.*)$ $1e$2 [L]
RewriteRule ^([^F]*)F(.*)$ $1f$2 [L]
RewriteRule ^([^G]*)G(.*)$ $1g$2 [L]
RewriteRule ^([^H]*)H(.*)$ $1h$2 [L]
RewriteRule ^([^I]*)I(.*)$ $1i$2 [L]
RewriteRule ^([^J]*)J(.*)$ $1j$2 [L]
RewriteRule ^([^K]*)K(.*)$ $1k$2 [L]
RewriteRule ^([^L]*)L(.*)$ $1l$2 [L]
RewriteRule ^([^M]*)M(.*)$ $1m$2 [L]
RewriteRule ^([^N]*)N(.*)$ $1n$2 [L]
RewriteRule ^([^O]*)O(.*)$ $1o$2 [L]
RewriteRule ^([^P]*)P(.*)$ $1p$2 [L]
RewriteRule ^([^Q]*)Q(.*)$ $1q$2 [L]
RewriteRule ^([^R]*)R(.*)$ $1r$2 [L]
RewriteRule ^([^S]*)S(.*)$ $1s$2 [L]
RewriteRule ^([^T]*)T(.*)$ $1t$2 [L]
RewriteRule ^([^U]*)U(.*)$ $1u$2 [L]
RewriteRule ^([^V]*)V(.*)$ $1v$2 [L]
RewriteRule ^([^W]*)W(.*)$ $1w$2 [L]
RewriteRule ^([^X]*)X(.*)$ $1x$2 [L]
RewriteRule ^([^Y]*)Y(.*)$ $1y$2 [L]
RewriteRule ^([^Z]*)Z(.*)$ $1z$2 [L]
# If there are no uppercase letters left, redirect
RewriteCond %{ENV:REDIRECT_STATUS} =200
RewriteRule ^((?!.*[A-Z]).+)$ $1 [R=302,NE,L]