I tried to get the Regex from this working:
mod_rewrite: replace underscores with dashes
But it leads to an endless loop for me and in case if only one underscore is in the URL it creates a redirect beginning at C: ...:
Something like:
http://localhost:7000/C://whatevercomesnext
Heres the Rule:
RewriteCond %{THE_REQUEST} _
RewriteRule ^(?news/.*/.*/[^/]*?)_([^/]*?_[^/]*)$ $1-$2 [N=10]
RewriteRule ^(?news/.*/.*/[^/]*?)_([^/_]*)$ $1-$2 [R=301,L]
It should convert urls like this:
http://localhost:.../news/2019/03/vollautomatisierte_abwicklung_eines_service_incidents_bei_retailer
Into this:
http://localhost:.../news/2019/03/vollautomatisierte-abwicklung-eines-service-incidents-bei-retailer
It's always the part after the last /
and only if there is the news part which hast to be converted. Nothing else needed, in fact all the other stuff should stay untouched.
Seems like removing those underscores is a very difficult problem since I found many solutions but no rule which works in general.
Now im totally confused. I testet my Rules via the htacces tester website: https://htaccess.madewithlove.be?share=7a4c3743-2f31-5489-aafe-1eebe41432ed
It worked only with a minor change in the RewriteCond.
The Tester just produced what i expected.
But when I test it locally the produced URL is a absolute mess. It generates URL is the base URL concatenated multiple times.
Probably for every single loop one time the complete URL....
No clue what to search for or how to fix this now.