Apache Lounge


About Forum Index Downloads Search Register Log in RSS X

Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.



A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Third-party Modules View previous topic :: View next topic
Reply to topic   Topic: Mod_rewrite for %20 black urls returning.

Joined: 03 Jun 2020
Posts: 1
Location: USA, NC, Monroe

PostPosted: Sun 07 Jun '20 20:28    Post subject: Mod_rewrite for %20 black urls returning. Reply with quote

Hello, I have an issue where we have Apache 2.4.4.X using mod_proxy_balancer pointing at Apache Tomcat 8. Our applications returning an outside url that has space in the url i.e. (www.example.com/myapp/ structs/ somedata/ We want to return this url without spaces because it fails. I have tried Apache mod_rewrite and the regex below within my vhost.conf file as well as using it with the Apache tomcat rewrite module inside of a rewrite.conf file with no success.

I confirmed it was working atleast running by using the trace8 on my mod_rewrite loglevel. But, what it doesnt do is clean up the spaces in question.

# remove spaces from start or after /
RewriteRule ^(.*/|)[\s%20]+(.+)$ $1$2 [L]

# remove spaces from end or before /
RewriteRule ^(.+?)[\s%20]+(/.*|)$ $1$2 [L]

# replace spaces by - in between
RewriteRule ^([^\s%20]*)(?:\s|%20)+(.*)$ $1-$2 [L,R]
Back to top
James Blond

Joined: 19 Jan 2006
Posts: 7329
Location: Germany, Next to Hamburg

PostPosted: Mon 08 Jun '20 12:33    Post subject: Reply with quote

The regex is not as you think it is

See https://regexper.com/#%5E%28.*%5C%2F%7C%29%5B%5Cs%2520%5D%2B%28.%2B%29%24

It replaces white space or % or 2 or 0

I suggest ( haven't tested it yet)

RewriteRule ^(\S*)\s+(\S*\s+.*)$ $1$2 [L]
Back to top

Joined: 16 Aug 2020
Posts: 333
Location: UK

PostPosted: Tue 13 Oct '20 16:59    Post subject: Reply with quote

Regex syntax aside, I think your problem here is mod_rewrite applies to requests not responses. You need mod_substitute to edit the responses returned by your Tomcat.

The logic you need will depend on whether Tomcat is sending response header redirects to the outside URL, or equally those URLs are embedded in the response body.

See https://httpd.apache.org/docs/2.4/mod/mod_substitute.html for sample syntax.
Back to top

Reply to topic   Topic: Mod_rewrite for %20 black urls returning. View previous topic :: View next topic
Post new topic   Forum Index -> Third-party Modules