2012-05-31 110 views
2

我试图获得请求的文件名,而没有路径 htaccess的RewriteCond。 REQUEST_FILENAME返回完整的绝对路径,但我只需要像test.php的文件名htaccess获取文件名无路径

我一直在寻找这个有很多,但无法找到任何东西,帮我摆脱困境。 感谢您提前做出任何回应!

编辑:

我试着做这样的事情:

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

基本上我想这样做:

URI:/测试/等等
检查_ test.php的存在(有下划线!)

+0

看看这个问题:http://stackoverflow.com/questions/470880/rewriterule-checking-file-in-rewriten-file-path-exists – Christopher

回答

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

我将*更改为+因此请求例如example.com/将不会重定向到_.php

+1

+1不错回答。 – anubhava

+0

非常感谢你! +1并被接受 – Fabian