Hi,

    I have the following rule that works well to remove trailing
    slashes from URLs:

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ $1 [R=301,L]

    This is done to prevent the non-slash URL from being treated as
    duplicate content with the URL with a slash.

    The problem is that there are exceptions, such as when we want to
    add query strings to the end of a URL:

    https://example.com/administrator/path/?cms_settings

    I've also tried a variation, like:

    https://example.com/administrator/path?cms_settings

    but somehow the slash is replaced back into the URL and I don't
    know where it comes from.

    Adding index.php to the path works properly because it's then not
    a directory:

    https://example.com/administrator/path/index.php?cms_settings

    Any ideas greatly appreciated.

    Thanks,
    Dave



What does the rewrite log say, exactly?

There's a tremendous amount of noise at trace5 (although probably only trace4 was apparently really necessary), and I've had trouble generally identifying the entries related to this specific rule, but here are a few entries I think represent what's happening.

https://webstage.example.com/administrator/sqlantern-joomla/php/?cms_settings

[Tue Jan 16 08:55:13.289102 2024] [rewrite:trace3] [pid 904886:tid 904938] mod_rewrite.c(493): [client 68.111.193.42:0] 68.195.193.42 - - [webstage.example.com/sid#560ba7f01a68][rid#7f2b1c0bc210/initial] applying pattern '^(.*)/$' to uri '/administrator/sqlantern-joomla/php/'

[Tue Jan 16 08:55:13.289129 2024] [rewrite:trace4] [pid 904886:tid 904938] mod_rewrite.c(493): [client 68.195.193.42:0] 68.111.193.42 - - [webstage.example.com/sid#560ba7f01a68][rid#7f2b1c0bc210/initial] RewriteCond: input='/administrator/sqlantern-joomla/php/' pattern='!-d' => matched

[Tue Jan 16 08:55:13.289143 2024] [rewrite:trace2] [pid 904886:tid 904938] mod_rewrite.c(493): [client 68.111.193.42:0] 68.195.193.42 - - [webstage.example.com/sid#560ba7f01a68][rid#7f2b1c0bc210/initial] rewrite '/administrator/sqlantern-joomla/php/' -> '/administrator/sqlantern-joomla/php'

[Tue Jan 16 08:55:13.289156 2024] [rewrite:trace2] [pid 904886:tid 904938] mod_rewrite.c(493): [client 68.111.193.42:0] 68.195.193.42 - - [webstage.example.com/sid#560ba7f01a68][rid#7f2b1c0bc210/initial] explicitly forcing redirect with https://webstage.example.com/administrator/sqlantern-joomla/php

[Tue Jan 16 08:55:13.289181 2024] [rewrite:trace1] [pid 904886:tid 904938] mod_rewrite.c(493): [client 68.111.193.42:0] 68.195.193.42 - - [webstage.example.com/sid#560ba7f01a68][rid#7f2b1c0bc210/initial] escaping https://webstage.example.com/administrator/sqlantern-joomla/php for redirect

[Tue Jan 16 08:55:13.289195 2024] [rewrite:trace1] [pid 904886:tid 904938] mod_rewrite.c(493): [client 68.111.193.42:0] 68.195.193.42 - - [webstage.example.com/sid#560ba7f01a68][rid#7f2b1c0bc210/initial] copying cms_settings to query string for redirect

[Tue Jan 16 08:55:13.289205 2024] [rewrite:trace1] [pid 904886:tid 904938] mod_rewrite.c(493): [client 68.111.193.42:0] 68.195.193.42 - - [webstage.example.com/sid#560ba7f01a68][rid#7f2b1c0bc210/initial] redirect to https://webstage.example.com/administrator/sqlantern-joomla/php?cms_settings [REDIRECT/301]

Thanks,
Dave

Reply via email to