-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.

kristopolous
  • 107
  • 3
  • That's unfortunate :-( Anyway, %{DOCUMENT_ROOT}content%{REQUEST_URI}\.php -f was what I was looking for. Been doing this stuff for 20 years and that STILL took me 2 hours to figure out. What a PITA. – kristopolous Aug 28 '15 at 07:26

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,308
  • 2
  • 17
  • 42
  • Indeed. I didn't realize it was the full path so I thought that there was a limitation in the syntax ... which sounded like some absurd, but understandable thing. Some gentleman who has since removed his comment, hinted at this, and then when I finally var_dump'd the $_SERVER in php, I was able to piece things together. I will clarify that this is possible, a misdiagnosis by me, and not a limitation of the syntax. – kristopolous Aug 28 '15 at 22:24