[英]how to change part of the url from capital to small letters after the directory path is changed apache/httpd
I want to be short and sweet. 我要矮小可爱。 My website address was this
https://www.example.com/ABCD/index.php
我的网站地址是
https://www.example.com/ABCD/index.php
To make it convenient for users, I changed the ABCD directory to abcd (small case). 为了方便用户,我将ABCD目录更改为abcd(小写)。 Now users type
https://www.example.com/abcd/index.php
现在用户输入
https://www.example.com/abcd/index.php
However if users come to my site from google, there it is still cached as https://www.example.com/ABCD/index.php
但是,如果用户从Google进入我的网站,该网站仍会缓存为
https://www.example.com/ABCD/index.php
and therefore they are not able to login. 因此他们无法登录。
I searched google and stack overflow and the closest effective I found is [here]. 我搜索了谷歌,然后发现堆栈溢出,我发现最接近的有效值是[这里]。 1 ie
1即
in http.conf 在http.conf中
<IfModule mod_rewrite.c>
RewriteMap lc int:tolower
</IfModule>
and in .htaccess 和.htaccess中
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule ^(.*)$ ${lc:$1} [R=301,L]
However it is also not working in my case. 但是,对于我来说,它也不起作用。 because it take users from
https://www.example.com/ABCD/index.php?gene=MYH7
因为它会吸引来自
https://www.example.com/ABCD/index.php?gene=MYH7
用户
to 至
https://www.example.com/var/www/html/example.com/?gene=MYH7
Could anyone experienced please help me to correct this rule. 任何有经验的人都可以帮助我纠正此规则。 All I want is to direct users to
https://www.example.com/abcd/index.php
我想要的只是将用户定向到
https://www.example.com/abcd/index.php
If they type 如果他们键入
https://www.example.com/ABCD/index.php
Here is the .htaccess in my web root directory. 这是我的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]
Change your rule with this one: 更改此规则:
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule ^ ${lc:%{REQUEST_URI}} [R=301,L,NE]
Changes: 变化:
DocumentRoot
path is appended by Apache as you're seeing in your redirect rule. DocumentRoot
路径,如您在重定向规则中所见。 RewriteRule
as your .htaccess might be in a sub-directory. RewriteRule
捕获值,因为您的.htaccess可能位于子目录中。 %{REQUEST_URI}
represents full path from site root %{REQUEST_URI}
代表网站根目录的完整路径 Make sure to use a new browser for testing. 确保使用新的浏览器进行测试。
It seems not to work inside a .htaccess. 在.htaccess中似乎不起作用。 I have the following working in my Apache config:
我的Apache配置中有以下工作:
<VirtualHost *:80>
rewriteengine on
RewriteMap lc int:tolower
RewriteRule "^/([A-Z]*)/(.*)$" "${lc:$1}/$2" [R=301]
</VirtualHost>
The following rule will lowercase the first part of the URL as soon as there is one uppercase character. 只要有一个大写字符,以下规则就会将URL的第一部分小写。
RewriteRule "^/([^/]*[A-Z][^/]*)/(.*)$" "${lc:$1}/$2" [R=301]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.