删除的.php与扩展的.htaccess不破的DirectoryIndex

编程入门 行业动态 更新时间:2024-10-24 14:17:54
本文介绍了删除的.php与扩展的.htaccess不破的DirectoryIndex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在我的.htaccess中重写它删除PHP扩展的文件,将例如 so/question.php 的到的 so/question 。

I have the following rewrite in my .htaccess file which removes the .php extension from files, converting for example so/question.php to so/question.

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L]

不过,这也打破了默认DirectoryIndex的行为,在刚刚输入的目录将重定向到索引文件的文件夹中,例如: so/answer 的显示的 so/answer/index.php 的

只要结合上述code与的DirectoryIndex的index.php 不实现这两个结果。

Simply combining the above code with DirectoryIndex index.php does not achieve both results.

有人可以帮助我结合这两种功能,或重写code排除的index.php文件,这将达到同样的效果?

Can someone help me combine these two functions, or rewrite the code to exclude index.php files, which would achieve the same result?

推荐答案

我想你只需要验证该文件存在这样的重写,这样你会离开404和DirectoryIndex的行为完好之前:

I'm thinking you just need to verify that the file exists prior to doing the rewrite, that way you'll leave 404 and directoryindex behaviours intact:

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php [NC,L]

(未测试)

更多推荐

删除的.php与扩展的.htaccess不破的DirectoryIndex

本文发布于:2023-11-01 20:00:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550270.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不破   php   htaccess   DirectoryIndex

发布评论

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

>www.elefans.com

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