Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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
END

IF (file exists) AND (file requested does not end with an extension)
    rewrite the URI
END
share|improve this question

1 Answer 1

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

 
discard

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.