【问题标题】:htaccess get filename without pathhtaccess 获取没有路径的文件名
【发布时间】:2012-05-31 14:44:01
【问题描述】:

我正在尝试使用 htaccess 获取请求的 不带路径的文件名 用于 RewriteCond。 REQUEST_FILENAME 返回完整的绝对路径,但我只需要像 test.php

这样的文件名

我一直在寻找这个,但找不到任何可以帮助我的东西。 感谢您提前回复!

编辑:

我正在尝试做这样的事情:

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

基本上我想这样做:

URI:/test/blah
检查 _test.php 是否存在(带下划线!)

【问题讨论】:

标签: .htaccess mod-rewrite


【解决方案1】:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/_$1.php -f
RewriteRule ^([^/]+)$ _$1.php [L]

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-13
    • 2011-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多