.htaccess;无需延期 [英] .htaccess; no extension required
本文介绍了.htaccess;无需延期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一些将无扩展名文件视为 PHP 文件的 .htaccess 代码.
I need some .htaccess code that will treat extensionless files as PHP files.
假设访问者访问www.mywebsite.com/dir1/dir2/file.name
,它会首先查看文件dir1/dir2/file.name
是否存在,然后如果它不存在,它会寻找 dir1/dir2/file.name.php
(所以使用 .php
扩展名).
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?
推荐答案
您可以编写重写规则,该规则仅在请求的文件不存在时生效.
You can write a rewriting rule which only takes into effect if the requested file doesn't exists.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !\.php$
RewriteRule ^(.*)$ $1.php [L]
这篇关于.htaccess;无需延期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文