I am setting up a local environment for testing using WAMP.

The app (angular app) sits in the /wamp/www/app/ directory. It makes requests to another api by sending requests to another route on its same server. (Specifically to /wamp/www/api/route)

We have a dev api server that exists at http://api.com. We have another test instance of the angular app at http://testapp.com/app/ that can send requests to http://api.com by pointing at http://testapp.com/api/route.

The way that this works in the test instance (non local) is that we have a .htaccess file at http://testapp.com/api/route that takes requests to http://testapp.com/api/route/* and sends them to http://api.com/*

The .htaccess file that does this is as follows:

<IfModule mod_rewrite.c>
    RewriteRule (.*) http://api.com/$1 [NC,P]

When I copy this .htaccess file to my /wamp/www/api/route/ directory I expect the following behavior:

What I want

The app will send a request to /wamp/www/api/route/stuff/ and the .htaccess file in /route/ takes that request, and proxies it to http://api.com/stuff

What I get

The app will send a request to /wamp/www/api/route/stuff/, and get a 404 back.

I've made sure that AllowOverride all is set, that the rewrite engine is on, and that mod-rewrite is enabled. I know the .htaccess file is being seen, because if I put garbage in it, i get a 500 instead of the 404, and my garbage gets into the log.

Any help would be much appreciated! Thanks.

After help from Purefan, I enabled rewrite logging, and since enabling, there have been no rewrite attempts, which would suggest that the rewrite rule is not ever being executed on the requests.

I have now tried to change the flow of how I call the rewrite rule.

I created a directory in the httpd config file, as follows:

<Directory "c:/wamp64/www/api/route">
    Options  +FollowSymLinks
    RewriteEngine on
    <IfModule mod_rewrite.c>
        RewriteRule (.*) http://api.com/$1 [NC,P]

And I still get the same behavior

  • 1
    Remember that you are rewriting the request based on URIs, not on folders. When apache gets a request it matches it to a set of rules in the VirtualHost blocks, if the request matches one of the VirtualHost blocks then the rules in that block process the request. When the app sends a request to localhost maybe the block with DocumentRoot /wamp/www/api/route/stuff intercepts it, but maybe it doesnt. Check your access logs, set one different per VirtualHost to make it easier – Purefan Feb 3 '17 at 15:53
  • 1
    You can also enable the rewrite log to help you see what is being rewritten and how – Purefan Feb 3 '17 at 15:54
  • The rewrite log sounds helpful. I'll look into this and check back in. Thanks! – Xgongiveittoya Feb 3 '17 at 15:55
  • A request is sent to the correct spot it would seem, but with the rewrite log on, nothing seems to be getting re-wrote ever. [03/Feb/2017:11:02:01 -0500] "GET /api/route/stuff – Xgongiveittoya Feb 3 '17 at 16:05

Thanks to Purefan, with the rewrite log enabled, I saw that the rewrite was attempting to rewrite, but then the request was never sent.

When I removed the P flag from the RewriteRule, it would rewrite the request, but then my headers were not added, because we were not proxying, which I need to do.

This then lead me to realize that the proxy was not working correctly, which immediately let to this solution:

In the httpd.conf file, change

#LoadModule proxy_module modules/mod_proxy.so


LoadModule proxy_module modules/mod_proxy.so


Enable mod_proxy if you want to proxy with the P flag on a re-write rule

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.