Re: [users@httpd] Stripping trailing slashes (again)

2024-07-11 Thread Frank Gingras
On Thu, Jul 11, 2024 at 6:55 AM Konstantin Kolinko 
wrote:

> чт, 13 июн. 2024 г. в 17:41, Dave Wreski  .invalid>:
> >
> > Hi,
> >
> > Some time ago I requested help with a rewrite rule to strip trailing
> slash(es) from all URLs in our joomla website, but I'm still having
> problems. This is the rule I am currently working with:
> >
> > RewriteRule ^(.*)/+$ https://linuxsecurity.com$1 [R=301,L]
> >
> > It works fine for any URL other than the homepage. Somehow for the
> homepage it creates an infinite loop, despite using "L", so perhaps I don't
> understand what it's doing. The (.*) is supposed to match any character,
> but there wouldn't be any preceding elements for the homepage.
> >
> > The problem as I see it is that, for the homepage, (.*) would be null,
> so $1 would also be null? This then creates the same URL as the one we're
> trying to fix.
>
> (.*) means "any character, 0 or more times".
> "0 times" here means that it matches an empty string. (Technically, it
> is an empty string, not null).
>
> URL for the home page is "/".
>
> (The first line of an HTTP 1.x request will be "GET / HTTP/1.1".
> By definition of the protocol, there has to be some text between the
> verb (GET) and the version.)
>
> A possible solution that I see is to make the first '/' explicit.
> adding it both to the regexp and to the replacement string:
>
>   RewriteRule ^/(.*)/+$ https://linuxsecurity.com/$1 [R=301,L]
>
> Alternatively, use '+' instead of '*' (meaning 1 or more times):
>
>   RewriteRule ^(.+)/+$ https://linuxsecurity.com$1 [R=301,L]
>
> Best regards,
> Konstantin Kolinko
>
> -
> To unsubscribe, e-mail: users-unsubscr...@httpd.apache.org
> For additional commands, e-mail: users-h...@httpd.apache.org
>
>
You're missing a key part of the engine here; in the per-directory context,
the leading / cannot be matched.  Per-directory means either .htaccess,
 or .  To make the rule work in both server and
per-directory context, use the conditional modifier:

^/?()

To stop loops, add a proper RewriteCond directive prior, and exclude
whatever URI you need.


Re: [users@httpd] Stripping trailing slashes (again)

2024-07-11 Thread Konstantin Kolinko
чт, 13 июн. 2024 г. в 17:41, Dave Wreski :
>
> Hi,
>
> Some time ago I requested help with a rewrite rule to strip trailing 
> slash(es) from all URLs in our joomla website, but I'm still having problems. 
> This is the rule I am currently working with:
>
> RewriteRule ^(.*)/+$ https://linuxsecurity.com$1 [R=301,L]
>
> It works fine for any URL other than the homepage. Somehow for the homepage 
> it creates an infinite loop, despite using "L", so perhaps I don't understand 
> what it's doing. The (.*) is supposed to match any character, but there 
> wouldn't be any preceding elements for the homepage.
>
> The problem as I see it is that, for the homepage, (.*) would be null, so $1 
> would also be null? This then creates the same URL as the one we're trying to 
> fix.

(.*) means "any character, 0 or more times".
"0 times" here means that it matches an empty string. (Technically, it
is an empty string, not null).

URL for the home page is "/".

(The first line of an HTTP 1.x request will be "GET / HTTP/1.1".
By definition of the protocol, there has to be some text between the
verb (GET) and the version.)

A possible solution that I see is to make the first '/' explicit.
adding it both to the regexp and to the replacement string:

  RewriteRule ^/(.*)/+$ https://linuxsecurity.com/$1 [R=301,L]

Alternatively, use '+' instead of '*' (meaning 1 or more times):

  RewriteRule ^(.+)/+$ https://linuxsecurity.com$1 [R=301,L]

Best regards,
Konstantin Kolinko

-
To unsubscribe, e-mail: users-unsubscr...@httpd.apache.org
For additional commands, e-mail: users-h...@httpd.apache.org



Re: [users@httpd] Stripping trailing slashes (again)

2024-06-13 Thread Eric Covener
> RewriteRule ^(.*)/+$ https://linuxsecurity.com$1 [R=301,END]
>
> I've also set logging to trace5 (even though none of the entries were above 
> trace4) - shouldn't it provide me with enough info to determine where/why 
> it's looping?

I think it loops because it redirects https://linuxsecurity.com/ to
https://linuxsecurity.com which the browser treats as
https://linuxsecurity.com/

You'll need to handle / with a condition or a slightly different regex.

-
To unsubscribe, e-mail: users-unsubscr...@httpd.apache.org
For additional commands, e-mail: users-h...@httpd.apache.org



Re: [users@httpd] Stripping trailing slashes (again)

2024-06-13 Thread Dave Wreski



Some time ago I requested help with a rewrite rule to strip
trailing slash(es) from all URLs in our joomla website, but I'm
still having problems. This is the rule I am currently working with:

RewriteRule ^(.*)/+$ https://linuxsecurity.com$1 [R=301,L]

It works fine for any URL other than the homepage. Somehow for the
homepage it creates an infinite loop, despite using "L", so
perhaps I don't understand what it's doing. The (.*) is supposed
to match any character, but there wouldn't be any preceding
elements for the homepage.

The problem as I see it is that, for the homepage, (.*) would be
null, so $1 would also be null? This then creates the same URL as
the one we're trying to fix.

First it appears to work properly (trimmed for legibility):

init rewrite engine with requested uri /
applying pattern '^(.*)/+$' to uri '/'
rewrite '/' -> 'https://linuxsecurity.com'
explicitly forcing redirect with https://linuxsecurity.com
escaping https://linuxsecurity.com for redirect
redirect to https://linuxsecurity.com [REDIRECT/301]

then it looks like it inits the rewrite engine again?

init rewrite engine with requested uri /, referer:
https://linuxsecurity.com/
applying pattern '^(.*)/+$' to uri '/', referer:
https://linuxsecurity.com/
rewrite '/' -> 'https://linuxsecurity.com', referer:
https://linuxsecurity.com/
explicitly forcing redirect with https://linuxsecurity.com,
referer: https://linuxsecurity.com/
escaping https://linuxsecurity.com for redirect, referer:
https://linuxsecurity.com/
redirect to https://linuxsecurity.com [REDIRECT/301], referer:
https://linuxsecurity.com/

This just loops repeatedly until it dies. I've also made sure
there's only one "RewriteEngine on" in the virtual host config and
the .htaccess. Would that even matter?

What am I doing wrong? I've tried a thousand variations of this to
no avail.

You will need to stop using .htaccess files to prevent looping, as a 
first step.  Edit your vhost.


I've removed the .htaccess in the document root and there are no other 
Includes in the vhost. I've also tried adding [END] but none of it has 
made any difference.


RewriteRule ^(.*)/+$ https://linuxsecurity.com$1 [R=301,END]

I've also set logging to trace5 (even though none of the entries were 
above trace4) - shouldn't it provide me with enough info to determine 
where/why it's looping?


If I remove the one RewriteEngine statement in my vhost config, it's 
clear that it does not process any RewriteRules at all.


dave






Re: [users@httpd] Stripping trailing slashes (again)

2024-06-13 Thread Eric Covener
>  despite using "L",

Looked at [END] ?

On Thu, Jun 13, 2024 at 10:41 AM Dave Wreski
 wrote:
>
> Hi,
>
> Some time ago I requested help with a rewrite rule to strip trailing 
> slash(es) from all URLs in our joomla website, but I'm still having problems. 
> This is the rule I am currently working with:
>
> RewriteRule ^(.*)/+$ https://linuxsecurity.com$1 [R=301,L]
>
> It works fine for any URL other than the homepage. Somehow for the homepage 
> it creates an infinite loop, despite using "L", so perhaps I don't understand 
> what it's doing. The (.*) is supposed to match any character, but there 
> wouldn't be any preceding elements for the homepage.
>
> The problem as I see it is that, for the homepage, (.*) would be null, so $1 
> would also be null? This then creates the same URL as the one we're trying to 
> fix.
>
> First it appears to work properly (trimmed for legibility):
>
> init rewrite engine with requested uri /
> applying pattern '^(.*)/+$' to uri '/'
> rewrite '/' -> 'https://linuxsecurity.com'
> explicitly forcing redirect with https://linuxsecurity.com
> escaping https://linuxsecurity.com for redirect
> redirect to https://linuxsecurity.com [REDIRECT/301]
>
> then it looks like it inits the rewrite engine again?
>
> init rewrite engine with requested uri /, referer: https://linuxsecurity.com/
> applying pattern '^(.*)/+$' to uri '/', referer: https://linuxsecurity.com/
> rewrite '/' -> 'https://linuxsecurity.com', referer: 
> https://linuxsecurity.com/
> explicitly forcing redirect with https://linuxsecurity.com, referer: 
> https://linuxsecurity.com/
> escaping https://linuxsecurity.com for redirect, referer: 
> https://linuxsecurity.com/
> redirect to https://linuxsecurity.com [REDIRECT/301], referer: 
> https://linuxsecurity.com/
>
> This just loops repeatedly until it dies. I've also made sure there's only 
> one "RewriteEngine on" in the virtual host config and the .htaccess. Would 
> that even matter?
>
> What am I doing wrong? I've tried a thousand variations of this to no avail.
>
>
>
>


-- 
Eric Covener
cove...@gmail.com

-
To unsubscribe, e-mail: users-unsubscr...@httpd.apache.org
For additional commands, e-mail: users-h...@httpd.apache.org



Re: [users@httpd] Stripping trailing slashes (again)

2024-06-13 Thread Frank Gingras
On Thu, Jun 13, 2024 at 10:41 AM Dave Wreski
 wrote:

> Hi,
>
> Some time ago I requested help with a rewrite rule to strip trailing
> slash(es) from all URLs in our joomla website, but I'm still having
> problems. This is the rule I am currently working with:
>
> RewriteRule ^(.*)/+$ https://linuxsecurity.com$1 [R=301,L]
>
> It works fine for any URL other than the homepage. Somehow for the
> homepage it creates an infinite loop, despite using "L", so perhaps I don't
> understand what it's doing. The (.*) is supposed to match any character,
> but there wouldn't be any preceding elements for the homepage.
>
> The problem as I see it is that, for the homepage, (.*) would be null, so
> $1 would also be null? This then creates the same URL as the one we're
> trying to fix.
>
> First it appears to work properly (trimmed for legibility):
>
> init rewrite engine with requested uri /
> applying pattern '^(.*)/+$' to uri '/'
> rewrite '/' -> 'https://linuxsecurity.com'
> explicitly forcing redirect with https://linuxsecurity.com
> escaping https://linuxsecurity.com for redirect
> redirect to https://linuxsecurity.com [REDIRECT/301]
>
> then it looks like it inits the rewrite engine again?
>
> init rewrite engine with requested uri /, referer:
> https://linuxsecurity.com/
> applying pattern '^(.*)/+$' to uri '/', referer:
> https://linuxsecurity.com/
> rewrite '/' -> 'https://linuxsecurity.com', referer:
> https://linuxsecurity.com/
> explicitly forcing redirect with https://linuxsecurity.com, referer:
> https://linuxsecurity.com/
> escaping https://linuxsecurity.com for redirect, referer:
> https://linuxsecurity.com/
> redirect to https://linuxsecurity.com [REDIRECT/301], referer:
> https://linuxsecurity.com/
>
> This just loops repeatedly until it dies. I've also made sure there's only
> one "RewriteEngine on" in the virtual host config and the .htaccess. Would
> that even matter?
>
> What am I doing wrong? I've tried a thousand variations of this to no
> avail.
>
>
>
>
>
You will need to stop using .htaccess files to prevent looping, as a first
step.  Edit your vhost.


[users@httpd] Stripping trailing slashes (again)

2024-06-13 Thread Dave Wreski

Hi,

Some time ago I requested help with a rewrite rule to strip trailing 
slash(es) from all URLs in our joomla website, but I'm still having 
problems. This is the rule I am currently working with:


RewriteRule ^(.*)/+$ https://linuxsecurity.com$1 [R=301,L]

It works fine for any URL other than the homepage. Somehow for the 
homepage it creates an infinite loop, despite using "L", so perhaps I 
don't understand what it's doing. The (.*) is supposed to match any 
character, but there wouldn't be any preceding elements for the homepage.


The problem as I see it is that, for the homepage, (.*) would be null, 
so $1 would also be null? This then creates the same URL as the one 
we're trying to fix.


First it appears to work properly (trimmed for legibility):

init rewrite engine with requested uri /
applying pattern '^(.*)/+$' to uri '/'
rewrite '/' -> 'https://linuxsecurity.com'
explicitly forcing redirect with https://linuxsecurity.com
escaping https://linuxsecurity.com for redirect
redirect to https://linuxsecurity.com [REDIRECT/301]

then it looks like it inits the rewrite engine again?

init rewrite engine with requested uri /, referer: 
https://linuxsecurity.com/

applying pattern '^(.*)/+$' to uri '/', referer: https://linuxsecurity.com/
rewrite '/' -> 'https://linuxsecurity.com', referer: 
https://linuxsecurity.com/
explicitly forcing redirect with https://linuxsecurity.com, referer: 
https://linuxsecurity.com/
escaping https://linuxsecurity.com for redirect, referer: 
https://linuxsecurity.com/
redirect to https://linuxsecurity.com [REDIRECT/301], referer: 
https://linuxsecurity.com/


This just loops repeatedly until it dies. I've also made sure there's 
only one "RewriteEngine on" in the virtual host config and the 
.htaccess. Would that even matter?


What am I doing wrong? I've tried a thousand variations of this to no avail.