-2

So I can clearly do this:

RewriteCond %{REQUEST_FILENAME}\.php -f

But I cannot do this:

RewriteCond some_directory/%{REQUEST_FILENAME}\.php -f

Furthermore, this also fails:

RewriteCond prefix%{REQUEST_FILENAME} -f

Presuming of course those files exist in the directory (duh!). Apparently, I can't prepend literal strings to TestStrings in RewriteCond stanzas in Apache 2.4

Anyone know how to do this? Thanks.

Note: Prepending string literals is done in the same way as appending. I had misattributed the problem as a limitation of the syntax. The truth was that "REQUEST_FILENAME" expanded to the full unix path, not the HTTP requested path, as I had originally thought.

tl;dr There is no special syntax provision for prefixing string literals; they work the same way they do in shell scripting, prefix%{variable}postfix is valid syntax.

Thanks for your time.

user535759
  • 107
  • 4

1 Answers1

2

The reason why that's not working is %{REQUEST_FILENAME} is the full path to the file (see http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond). If I understand correctly what I think you're trying to accomplish, you'd do it with multiple conditions using RewriteCond backreferences. I didn't test this, but I think it'd be something like the following:

RewriteCond %{REQUEST_FILENAME} (.*)/([^/]+)$
RewriteCond %1/prefix/%2 -f
sa289
  • 1,418