3

I'm trying to get the requested filename without the path with htaccess for a RewriteCond. REQUEST_FILENAME returns the full absolute path, but I only need the filename like test.php

I've been searching for this a lot but couldn't find anything that helped me out. Thanks for any responses in advance!

Edit:

Im trying to do something like this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond _%{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]*)$ _$1.php [L]

Basically I want to do this:

URI: /test/blah
Check if _test.php exists (with underscore!)

Fabian
  • 3,465
  • 4
  • 34
  • 42
  • Take a look at this question: http://stackoverflow.com/questions/470880/rewriterule-checking-file-in-rewriten-file-path-exists – Christopher May 31 '12 at 16:02

1 Answers1

7
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/_$1.php -f
RewriteRule ^([^/]+)$ _$1.php [L]

I changed * to + so requests for e.g. example.com/ will not redirect to _.php

Gerben
  • 16,747
  • 6
  • 37
  • 56