Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using the following rewrite url to get prettier urls:

RewriteRule (\d+)/(.+) $2?companyId=$1  [NC,L,B,QSA,NE]

The url /invoices.php?companyId=123 can for example be expressed as /123/invoices.php. I tested and it works fine.

The problem is that some of my php files references images and javascript by relative urls, example js/jquery.js. I thought that these files would also be covered by my rewrite url which is pretty generic, but apparently it doesn't and returns a 404 instead.

Example: Accessing /123/js/jquery.js in the browser returns a 404 error: The requested URL /js/jquery.js was not found on this server. Note how the error message refers to the file name which has been rewritten to the correct file name. If i copy-paste the url from the error message into my browser's url field (ommiting the rewrite rule) it returns the file!

The only difference between the php file (which works) and my images/javascript files is that the latter reside in sub directories instead of at root level.

Putting my php file in the /test sub folder yields the very same issue, example:

/35/test/invoices.php => The requested URL /test/invoices.php was not found on this server.

Again, mod_rewrite has changed the path as expected but apache fails to find the file. Accessing it directly works fine.

The problem with javascripts and images can easily be resolved by using absolute paths since they don't need the companyId parameter. However, down the road I may want to structure my php files in sub directories so I need a fix for this now.

Does anyone know why apache cannot find files in subdirectories when the path has been through the rewrite module?



share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.