.htaccess;无需延期
我需要一些 .htaccess 代码,将无扩展名文件视为 PHP 文件。
假设访问者访问www.mywebsite.com/dir1/dir2/file.name
,它首先会查找文件dir1/dir2/file.name
是否存在,如果不存在如果存在,它将查找 dir1/dir2/file.name.php
(因此带有 .php
扩展名)。
这在某种程度上可能吗?
I need some .htaccess code that will treat extensionless files as PHP files.
Suppose the visitors visits www.mywebsite.com/dir1/dir2/file.name
, it will first look the file dir1/dir2/file.name
exists and if it not exists, it will look for dir1/dir2/file.name.php
(so with .php
extension).
Is that possible in some way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以编写一个重写规则,该规则仅在请求的文件不存在时才生效。
You can write a rewriting rule which only takes into effect if the requested file doesn't exists.
你应该看看 Apache 的
选项
指令,最具体的是 http://httpd.apache.org/docs/2.0/content-negotiation.html 选项,您可以将其包含在.htaccess
文件即可实现此目的。添加到您的
.htaccess
:You should have a look at Apache's
Options
directive, most specifically the http://httpd.apache.org/docs/2.0/content-negotiation.html option which you can include in your.htaccess
file and will do just that.Add to your
.htaccess
:好吧,答案是答案的组合。我需要在我的 Apache 配置中添加
Options +MultiViews
。然后我将Andrews
的回答扩展到以下内容:问候并非常感谢!
凯文
Ok, the answer was a combination of answers. I needed to add
Options +MultiViews
in my Apache configuration. Then I extendAndrews
answer to the following:Regards and many thanks!
Kevin