htaccess的;无需扩展 [英] .htaccess; no extension required
本文介绍了htaccess的;无需扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要的.htaccess code表示将把扩展名的文件作为PHP文件。
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).
这有可能以某种方式?
推荐答案
您可以写一个重写规则,只需要生效,如果所需的文件不存在。
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屋!
查看全文