![](/img/trans.png)
[英]How to write regular expression that covers small and capital letters of a specific word?
[英]how to change part of the url from capital to small letters after the directory path is changed apache/httpd
我要矮小可爱。 我的网站地址是https://www.example.com/ABCD/index.php
为了方便用户,我将ABCD目录更改为abcd(小写)。 现在用户输入https://www.example.com/abcd/index.php
但是,如果用户从Google进入我的网站,该网站仍会缓存为https://www.example.com/ABCD/index.php
因此他们无法登录。
我搜索了谷歌,然后发现堆栈溢出,我发现最接近的有效值是[这里]。 1即
在http.conf中
<IfModule mod_rewrite.c>
RewriteMap lc int:tolower
</IfModule>
和.htaccess中
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule ^(.*)$ ${lc:$1} [R=301,L]
但是,对于我来说,它也不起作用。 因为它会吸引来自https://www.example.com/ABCD/index.php?gene=MYH7
用户
至
https://www.example.com/var/www/html/example.com/?gene=MYH7
任何有经验的人都可以帮助我纠正此规则。 我想要的只是将用户定向到https://www.example.com/abcd/index.php
如果他们键入
https://www.example.com/ABCD/index.php
这是我的Web根目录中的.htaccess。
RewriteEngine On
# Added by Mian to direct all traffic to https
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.example.org%{REQUEST_URI} [NE,L,R]
# Added by Mian for url capital to small.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule ^(.*)$ ${lc:$1} [R=301,L]
更改此规则:
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule ^ ${lc:%{REQUEST_URI}} [R=301,L,NE]
变化:
DocumentRoot
路径,如您在重定向规则中所见。 RewriteRule
捕获值,因为您的.htaccess可能位于子目录中。 %{REQUEST_URI}
代表网站根目录的完整路径 确保使用新的浏览器进行测试。
在.htaccess中似乎不起作用。 我的Apache配置中有以下工作:
<VirtualHost *:80>
rewriteengine on
RewriteMap lc int:tolower
RewriteRule "^/([A-Z]*)/(.*)$" "${lc:$1}/$2" [R=301]
</VirtualHost>
只要有一个大写字符,以下规则就会将URL的第一部分小写。
RewriteRule "^/([^/]*[A-Z][^/]*)/(.*)$" "${lc:$1}/$2" [R=301]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.