Yes, should work.
I just tested the iRule, with small change to match my lab environment.
Headers without iRule:
HTTP/1.1 200 OK
Date: Thu, 06 Apr 2017 11:16:07 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16
X-Powered-By: PHP/5.4.16
Set-Cookie: Chocolate=Price%3D1pound; expires=Thu, 06-Apr-2017 11:17:07 GMT
Set-Cookie: Coconut=Price%3D2pounds; expires=Thu, 06-Apr-2017 11:18:07 GMT
Content-Length: 503
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
iRule:
when HTTP_RESPONSE {
if { ( [HTTP::status] eq "200" ) and ( [HTTP::header exists X-Powered-By] ) } {
HTTP::header replace X-Powered-By "ok"
}
}
Headers after iRule applied to virtual server:
HTTP/1.1 200 OK
Date: Thu, 06 Apr 2017 11:18:43 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16
X-Powered-By: ok
Set-Cookie: Chocolate=Price%3D1pound; expires=Thu, 06-Apr-2017 11:19:43 GMT
Set-Cookie: Coconut=Price%3D2pounds; expires=Thu, 06-Apr-2017 11:20:43 GMT
Content-Length: 497
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8