skip to Main Content

Im able to get all my urls to redirect to lower case using the following in my conf file

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

works like a charm…

The issue is though, I really need this to apply only to URLs www.example.com/this-doesnt-change/Random_Random_111

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

or even www.example.com/this-doesnt-change/Random

Basically anything after www.example.com/this-doesnt-change/

I’ve tried replacing

RewriteCond %{REQUEST_URI} [A-Z]

with

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

but all I get is "too many redirects" error

Or should I be restricting the rule to this path using a function of the conf file?

Any insight is appreciated

EDIT:

the .htaccess file



##
# 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)+.*)$ $1-$2$3 [N,DPI]
RewriteRule ^([^s%20]+)(?:s|%20)+(.*)$ /$1-$2 [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/$1 [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-]+)_([^/]+)$ /$1/$2 [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

the

2

Answers


  1. Chosen as BEST ANSWER

    Thank you Ryszard Czech as your answer ( comment) worked ( I initially put the code in the wrong place)

    Replaced the code to this and it worked like a charm.

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

  2. Use

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

    Regex demo here

    Regex explanation

    --------------------------------------------------------------------------------
      ^                        the beginning of the string
    --------------------------------------------------------------------------------
      (                        group and capture to 1:
    --------------------------------------------------------------------------------
        /this-doesnt-             '/this-doesnt-change/'
        change/
    --------------------------------------------------------------------------------
        .*                       any character except n (0 or more times
                                 (matching the most amount possible))
    --------------------------------------------------------------------------------
      )                        end of 1
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search