Your iRule works without any problem on my lab BIG-IP. I don't see any error messages in the /var/log/ltm file. I'm using 14.1.0.3. You could try removing the comments in the iRule. I've seen comments in the iRule being responsible for error messages.
# curl -v http://10.23.98.218 -H "host: www.example.com"
* Rebuilt URL to: http://10.23.98.218/
* Trying 10.23.98.218...
* Connected to 10.23.98.218 (10.23.98.218) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.40.0
> Accept: */*
> host: www.example.com
>
* HTTP 1.0, assume close after body
< HTTP/1.0 302 Moved Temporarily
< Location: http://example.com/
< Server: BigIP
* HTTP/1.0 connection set to keep alive!
< Connection: Keep-Alive
< Content-Length: 0
<
* Connection #0 to host 10.23.98.218 left intact
#