Mod_rewrite replace all slashes (/)

I'm having problems with the Next [N] flag in mod_rewrite

I want to replace ALL slashes (/) in url with an underscore. I have tried many regular expressions that work well for any other language, but mod_rewrite does not. How:

/ _ [N] or (.*)/(.*) $1_$2 [N] 

But mod_rewrite seems to go into an infinite loop.

I need a procedure that works for the X number of slashes, not limited to, for example, 3 or 4 slashes.

Thanks.

+2
source share
1 answer

The solution should be very similar to the solution presented in mod_rewrite: replace dashes with underscores .

You essentially need two general rules, the first of which uses the Next [N] flag, but with the addition of a check so that there are always 2 slashes (which you are missing). Then you need the final rule to complete it with redirection and enable the last flag [L].

Hope that helps

0
source

Source: https://habr.com/ru/post/1215273/


All Articles