Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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've got a rewriterule that works for everything except the lib folder. The rule is

RewriteRule ^/uk(.*) $1

It's one of a much more complex set of rules but I've disabled all but this one. The rule works fine for everything but the contents of the lib folder:

http://site.local/lib/cookies.js works but http://site.local/uk/lib/cookies.js doesn't.

Every other path on the site redirects fine eg:

http://site.local/uk/course/view.php?id=15 goes to http://site.local/course/view.php?id=15

  • Other folders with only three letters in their name work.
  • uk/otherpath/lib works.
  • There is no htaccess file in the lib folder
  • There is no htaccess file in the site root (the rules are in the virtual host definition)
  • The issue occurs on Ubuntu and RedHat (dev and production)
  • The issue occurs on another moodle site on a colleagues workstation
  • The permissions on the lib folder are identical to the rest of the directory tree

What am I missing?

--- EDIT ---

RewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 9

Gives me - - [22/Sep/2011:11:21:57 +0100] [site.local/sid#7f15a0b345d0][rid#7f15a0e1b270/initial] (2) init rewrite engine with requested uri /uk/lib/cookies.js - - [22/Sep/2011:11:21:57 +0100] [site.local/sid#7f15a0b345d0][rid#7f15a0e1b270/initial] (3) applying pattern '^/uk(.*)' to uri '/uk/lib/cookies.js' - - [22/Sep/2011:11:21:57 +0100] [site.local/sid#7f15a0b345d0][rid#7f15a0e1b270/initial] (2) rewrite '/uk/lib/cookies.js' -> '/lib/cookies.js' - - [22/Sep/2011:11:21:57 +0100] [site.local/sid#7f15a0b345d0][rid#7f15a0e1b270/initial] (2) local path result: /lib/cookies.js - - [22/Sep/2011:11:21:57 +0100] [site.local/sid#7f15a0b345d0][rid#7f15a0e1b270/initial] (1) go-ahead with /lib/cookies.js [OK] - - [22/Sep/2011:11:21:57 +0100] [site.local/sid#7f15a0b345d0][rid#7f15a0e232b0/initial] (2) init rewrite engine with requested uri /favicon.ico - - [22/Sep/2011:11:21:57 +0100] [site.local/sid#7f15a0b345d0][rid#7f15a0e232b0/initial] (3) applying pattern '^/uk(.*)' to uri '/favicon.ico' - - [22/Sep/2011:11:21:57 +0100] [site.local/sid#7f15a0b345d0][rid#7f15a0e232b0/initial] (1) pass through /favicon.ico

So it looks to me like that should work?

share|improve this question
Enable RewriteLog and set RewriteLogLevel to 9 to see what does it say? – quanta Sep 22 '11 at 10:21
Did you try grep -ir lib /path/to/your/apache/config yet to see if there's something lib related lurking somewhere? – Janne Pikkarainen Sep 22 '11 at 10:28
Good spot, I've added to the question. – Andrew Hancox Sep 22 '11 at 10:28
What output did you get on the browser? Did you take a look at error_log? – quanta Sep 22 '11 at 17:57
up vote 1 down vote accepted

The question got answered on serverfault. It turns out there's some scary default behaviour whereby if you write the rule in the virtualhost and don't explicitly redirect to a path starting with %{DOCUMENT_ROOT} it looks for matching paths in the root of your file system first. I've appended the answer below:

After messing about with this on my local machine, it would appear that Apache is rewriting to /lib on your file system before checking for the document_root/lib directory.

You should change your Rewrite to:

RewriteRule ^/uk(.*) %{DOCUMENT_ROOT}$1
share|improve this answer

Your Answer


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

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