Home Apache rewrite configuration not working
 I have a use case where I only want to forward the request to localhost only if url of the below forms and ItemType equals x. http://example.com:15790/d/ItemType=x&id=3 http://example.com:15790/ItemType=(anything) RewriteCond %{THE_REQUEST} !\s/d/ RewriteCond %{QUERY_STING} (?:^|&)ItemType=(x)(?:&|$) [NC] RewriteRule ^/(.*)$ http://google.com/$1 [R=301,L,NC] RewriteCond %{THE_REQUEST} \s/d/ RewriteCond %{QUERY_STRING} (?:^|&)ItemType=(x)(?:&|$) [NC] RewriteRule ^/?d/(.*)$http://localhost:15790/$1 [P,NE,L,NC]  The above configuration is not working for me. First rewriting works fine but second is also using the first rewriting. Can somebody explain me what I am doing wrong? Note:I am new to this rewriting URLs. Also can somebody help me with where I can find the logs?