简体   繁体   English

更改目录路径后,如何将部分url从大写字母更改为小写字母apache / httpd

[英]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: 变化:

  • Redirect path starts with a trailing slash. 重定向路径以斜杠开头。 If trailing slash is missing then DocumentRoot path is appended by Apache as you're seeing in your redirect rule. 如果缺少尾部斜杠,那么Apache会附加DocumentRoot路径,如您在重定向规则中所见。
  • Avoid capturing value from 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.

相关问题 如何编写涵盖特定单词的大小写字母的正则表达式? - How to write regular expression that covers small and capital letters of a specific word? 通过 RegExp 匹配大写字母和小写字母 - Match capital letters and small letters by RegExp 如何替代小写字母的大写字母串并找出不可替代的 - How to substitute the small letters in a string with capital letters and also to find out no of substitutions 寻找删除边上空格的方法,将所有字母更改为小写,第一个字母为大写字母 - Looking for method to remove spaces on sides, change all letters to small with first letter as capital letter 查找大写字母的简单正则表达式返回小写字母 - Simple regex expression to find capital letters is returning small letters 如何提示用户输入由大写,小写字母,数字和符号组成的强密码? - how to prompt user to enter a strong password which consists of capital, small letters, numbers and symbol? 正则表达式匹配3个大写字母后跟一个小写字母后跟3个大写字母? - Regular expression to match 3 capital letters followed by a small letter followed by 3 capital letters? python匹配大写和小写字母,而不使用上下 - python match capital and small letters without using lower or upper 正则表达式匹配第一个大写字母,然后是一个或多个小写字母 - Regex matching first capital letter followed by one or more small letters 如何匹配以大写字母和非大写字母开头的单词? - How Do I Match Words That Start With Capital And Non Capital Letters?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM