我正在尝试使用htaccess获取RewriteCond的请求的不带路径的文件名. REQUEST_FILENAME返回完整的绝对路径,但是我只需要像 test.php
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!
我正在尝试执行以下操作:
Im trying to do something like this:
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond _%{REQUEST_FILENAME}.php -f RewriteRule ^([^/]*)$ _$1.php [L]
- 在浏览器中键入的URL如下所示: example/test
- RewriteRule请求的文件为: example/_test.php
- 我尝试使用RewriteCond _%{REQUEST_FILENAME}.php -f首先检查文件是否存在
- The URL typed in the browser looks like this: example/test
- The File that will be requestested by the RewriteRule is: example/_test.php
- With RewriteCond _%{REQUEST_FILENAME}.php -f i tried to check if the file exists first
基本上我想这样做:
URI:/test/blah 检查_ test.php 是否存在(带下划线!)
URI: /test/blah Check if _test.php exists (with underscore!)
推荐答案RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/_$1.php -f RewriteRule ^([^/]+)$ _$1.php [L]
我将*更改为+,因此要求example/不会重定向到_.php
I changed * to + so requests for e.g. example/ will not redirect to _.php
更多推荐
htaccess获取没有路径的文件名
发布评论