1

I'm dealing with requests from a proprietary client, that sometimes uses back- rather than forward-slashes: GET /path\to\the\file.txt, and I'd like to straighten them all out.

mod_rewrite can replace one at a time:

RewriteRule ^(.*)\\+(.*) $1/$2 [QSA]

but how would I replace all such occurrences at once, like sed's /g modifier?

Mikhail T.
  • 2,338
  • 1
  • 24
  • 55
  • Beware of order/interaction with existing rules, especially B/BNP/BCTLS/BNE.. depending on the client you are working with, at least one explicit redirect may be preferable to internal rewrites. – anx Aug 16 '23 at 19:46
  • Considering this vendor's software quality, I doubt, this client can handle redirects _at all_... – Mikhail T. Aug 16 '23 at 20:36

1 Answers1

1

Should be possible with something like:

RewriteRule ^/([^\\]*)\\([^\\]*\\.*) /$1/$2 [N]
RewriteRule ^/([^\\]*)\\([^\\]*)$ /$1/$2

https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_n

The [N] flag causes the ruleset to start over again from the top, using the result of the ruleset so far as a starting point. Use with extreme caution, as it may result in loop.

anx
  • 8,963
  • 5
  • 24
  • 48
Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129