我坚持尝试将特定路径中的所有网址重定向到小写

I'm stuck at trying to redirect all urls in specific path to lower case

我能够使用我的 conf 文件中的以下内容将我所有的 url 重定向到小写

RewriteEngine On
RewriteMap  lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:} [R=301,L]

很有魅力...

问题是,我真的需要它只应用于 URL www.example.com/this-doesnt-change/Random_Random_111

www.example.com/this-doesnt-change/Random/Random_111

甚至www.example.com/this-doesnt-change/Random

基本上www.example.com/this-doesnt-change/

之后的任何东西

我试过更换

RewriteCond %{REQUEST_URI} [A-Z]

RewriteCond %{REQUEST_URI} this-doesnt-change/.+

但我得到的只是“重定向太多”错误

或者我应该使用 conf 文件的功能将规则限制到这个路径?

感谢任何见解

编辑:

.htaccess 文件



##
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
#
# The line 'Options +FollowSymLinks' may cause problems with some server configurations.
# It is required for the use of mod_rewrite, but it may have already been set by your 
# server administrator in a way that disallows changing it in this .htaccess file.
# If using it causes your site to produce an error, comment it out (add # to the 
# beginning of the line), reload your site in your browser and test your sef urls. If 
# they work, then it has been set by your server administrator and you do not need to 
# set it here.
##

RewriteRule \.(jpe?g|png|gif|ico|bmp|pdf|docx?|txt|css|js)$ - [L,NC]

RewriteRule ^([^\s%20]+)(?:\s|%20)+([^\s%20]+)((?:\s|%20)+.*)$ - [N,DPI]
RewriteRule ^([^\s%20]+)(?:\s|%20)+(.*)$ /- [L,R=301,DPI]


RewriteRule ^(server-info|server-status) - [L]


RewriteCond %{REQUEST_URI} !pagespeed



## No directory listings
IndexIgnore *

## Can be commented out if causes errors, see notes above.
Options +FollowSymlinks
Options -Indexes

<IfModule mod_headers.c>
Header always set X-Content-Type-Options "nosniff"
</IfModule>

## Mod_rewrite in use.


RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/ [L,R=301]






## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site then comment out the operations listed 
# below by adding a # to the beginning of the line.
# This attempts to block the most common type of exploit `attempts` on Joomla!
#
# Block any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.



RewriteRule ^(this-doesnt-change/[a-zA-Z-]+)_([^/]+)$ // [R=301,L]

#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects

##
# Uncomment the following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##

# RewriteBase /

## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.

php_value upload_max_filesize 5M
php_value post_max_size 10M

谢谢 Ryszard Czech 因为你的回答(评论)有效(我最初把代码放在错误的地方)

将代码替换为此,效果非常好。

RewriteEngine On
RewriteMap  lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule ^(/this-doesnt-change/.*) ${lc:} [R=301,L]

使用

RewriteRule ^(/this-doesnt-change/.*) ${lc:} [R=301,L]

Regex demo here

正则表达式解释

--------------------------------------------------------------------------------
  ^                        the beginning of the string
--------------------------------------------------------------------------------
  (                        group and capture to :
--------------------------------------------------------------------------------
    /this-doesnt-             '/this-doesnt-change/'
    change/
--------------------------------------------------------------------------------
    .*                       any character except \n (0 or more times
                             (matching the most amount possible))
--------------------------------------------------------------------------------
  )                        end of