htaccess获取没有路径的文件名

编程入门 行业动态 更新时间:2024-10-23 02:04:42
本文介绍了htaccess获取没有路径的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用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获取没有路径的文件名

本文发布于:2023-10-31 18:59:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546988.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件名   路径   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!