Server Fault is a question and answer site for system and network administrators. 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 need to set up an apache RewriteRule in order to have this behavior: => index.php?module=foo&action=&args= => index.php?module=foo&action=bar&args= => index.php?module=foo&action=bar&args=baz => index.php?module=foo&action=bar&args=baz/foobaz

I wroted this regex:

RewriteRule ^(.[^/]*)(\/)?(.[^/]+)?(\/)?(.+)?$ index.php?module=$1&action=$3&args=$5 [L,QSA]

It works well, i only need to tell apache to ignore all urls that end with some specific estension (for example, .jpg, .png, .css, .js, .gif, etc..); Those should be treated as normal, e.g. should show the CSS file (is it exists).

Any idea?

share|improve this question
up vote 1 down vote accepted

An easy way to get around it is this

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.[^/]*)(\/)?(.[^/]+)?(\/)?(.+)?$ index.php?module=$1&action=$3&args=$5 [L,QSA]

That tells apache to not run the rule if the file is a real file on the system that can be served up.. Now you if you want to do it for just image/css/js files you could probably do

RewriteCond %{REQUEST_FILENAME} !^(.*).(js|jpg|css|gif)$
RewriteRule ^(.[^/]*)(\/)?(.[^/]+)?(\/)?(.+)?$ index.php?module=$1&action=$3&args=$5 [L,QSA]

That one is untested but you get the idea.

share|improve this answer
+1 ... but the second RewriteCond regexp would be more precise if the period preceding the file extension were escaped. – danlefree Nov 30 '10 at 12:04
Im already using the first rule; In fact in my case the problems come when files doesnt exists! I'll try the second regex! – Strae Nov 30 '10 at 13:17

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.