0

I've been through all tagged questions here and on SO, but my problem is different because of either/both needing to replace "." with "_" comes after a particular path and I'm running through a proxypass.

I am trying to change:

http://somedomainname.com/grafana/dashboard/db/generic-ping?var-device=SF-some.machinename.com

to:

http://somedomainname.com/grafana/dashboard/db/generic-ping?var-device=SF-some_machinename_com

Code:

Options +FollowSymLinks

RewriteEngine On

ProxyPreserveHost On

ProxyPass /grafana http://100.65.7.97:3000

ProxyPassReverse /grafana http://100.65.7.97:3000

I've tried many things after hours of scouring serverfault/stackoverflow/webmasters.stackexchange/google etc. But nothing I try is successfully redirecting. I'm not sure why.

Some of the things I've tried (and variations on them):

RewriteRule ^([^\.]*)\ (.*)$ $1_$2 [E=%E2:yes,N]
RewriteCond %{ENV:%E2} yes
RewriteRule (.*) http://%{HTTP_HOST}$1 [R=301,L]

...

RewriteRule       ^(/?grafana/dashboard/db/.*/[^/]*?).([^/]*?.[^/]*)$ $1_$2 [N]
RewriteRule       ^(/?grafana/dashboard/db/.*/[^/]*?).([^/.]*)$       $1_$2 [R=301]

...

RewriteCond %{REQUEST_URI} ^(.*).(.*).(.*)/$
RewriteRule (.*).(.*).(.*)/ http://somedomainname.com/grafana/dashboard/db/$1_$2_$3/ [R=301]

...and many others...

Could this be an issue because I'm also using proxypass? Maybe I'm just overlooking something simple? Any help is appreciated.

TryTryAgain
  • 1,152
  • 5
  • 22
  • 41

1 Answers1

1

var-device=SF-some.machinename.com is part of the QUERY_STRING, not the REQUEST_URI. Your last rule looks kinda correct except you need to escape the periods.

RewriteCond %{QUERY_STRING} (.*)\.(.*)\.(.*)
RewriteRule ^/grafana/dashboard/db/generic-ping /grafana/dashboard/db/generic-ping?%1_%2_%3 [R=301]

where %1 = var-device=SF-some, %2 = machinename and %3 = com.

Mark Wagner
  • 18,019
  • 2
  • 32
  • 47
  • Works! Great description, thank you for clarifying the `QUERY_STRING` part, and for pointing out the need to escape the periods. This was a learning experience. Your help is very much appreciated. – TryTryAgain Mar 04 '16 at 02:38
  • any chance you'd be able to help out with this similar question?: http://serverfault.com/questions/762198/mod-rewrite-with-multiple-query-strings ...your help would be greatly appreciated. – TryTryAgain Mar 09 '16 at 17:11