Webmasters Stack Exchange is a question and answer site for pro webmasters. 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 have the following .htaccess:

#If the requested URI does not end with an extension OR if the URI ends with .php*
#(where * is optionally one or more numbers)
RewriteCond %{REQUEST_URI} !\.[^/]+$ [NC,OR]
RewriteCond %{REQUEST_URI} \.php[s0-9]*$ [NC]

#Then serve the URI via the mapper
RewriteRule .* /mapper.php?uri=%{REQUEST_URI} [L,QSA]

I would like to add the following conditions to it:

  • The file actually exists
  • And is without an extension

So the entire file would do something like this:

IF (requested URI does not end with an extension) OR (URI ends with .php*) THEN
    rewrite the URI

IF (file exists) AND (file requested does not end with an extension)
    rewrite the URI
share|improve this question
up vote 1 down vote accepted

Perhaps something like this:

RewriteCond %{REQUEST_FILENAME} -s
RewriteCond %{REQUEST_URI} \.php[s0-9]*$ [NC]
RewriteRule .* /mapper.php?uri=%{REQUEST_URI} [L,QSA]

RewriteCond %{REQUEST_FILENAME} -s
RewriteCond %{REQUEST_URI} !\.[^/]+$ [NC]
RewriteRule .* /mapper.php?uri=%{REQUEST_URI} [L,QSA]
share|improve this answer
No, it's not working.... What is the -s? For files it's not -f? – Activist Jul 20 '11 at 14:18
-s is for a file with size (ie. not empty) -f is for any file. See documentation. – matthew Jul 20 '11 at 14:22
Thanks! Your example showed me that we ca use many RewriteRule with [L]! – Activist Jul 20 '11 at 15:57

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.