I have a website which is setup with akamai. My domain and subdomains are mapped onto an Akamai IP.

I have written an Apache rewrite which does an internal URL X to another internal URL Y. This rewrite works fine as long as I am testing in my local setup or for those subdomains which are not mapped onto Akamai but directly onto my Public IP.

My suspicion is that while rewriting the request apache is not able to resolve the IP of the app server correctly.

When I add entries to my /etc/hosts file pointing the domain/subdomain to my internal IP the rewrites work.

Now, I have a huge list of subdomains and it can grow as well. Is there another way to fix this problem without having to make entries in the /etc/hosts file ?

I would much appreciate your thoughts.

  • What kind of a rewrite are you doing exactly, can you show an example?
    – Pekka
    Feb 10, 2012 at 10:57
  • This question should be asked on server fault
    – thenetimp
    Feb 10, 2012 at 11:03
  • Here is the rewrite rule which I have..RewriteRule ^/(context)/(sub-context)(-)([-a-z0-9A-Z]*)/(.*)$ /$1/$2/$5 [P,L]
    – nuttyket
    Feb 10, 2012 at 11:45

2 Answers 2


Yes - use a different DNS server, or re-write the URL to use a hostname which works correctly.

However the net effect is the same as changing the entry in your hosts file. But if you are not sending back a redirect from the rewrite, then you'll get marginally better performance by using the loopback adapter rather than (the address of a) real NIC. So just put it in you hosts file as but more importantly this address should never change.


I'm actually quite surprised to hear that the rewrite rule you say you have:

RewriteRule ^/(context)/(sub-context)(-)([-a-z0-9A-Z]*)/(.*)$ /$1/$2/$5 [P,L]

works at all, since according to the documentation it shouldn't:

"^/somepath(.*) /otherpath$1 [P]     doesn't make sense, not supported"

If you want to use the [P] flag, your rewrite target should be a full URL. However, I very much suspect that the [P] flag is, in fact, not what you want, and that removing it might fix the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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