运行没有扩展名的PHP页面 [英] Run PHP pages without an extension

查看:73
本文介绍了运行没有扩展名的PHP页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在没有 .php 扩展名的apache Web服务器上运行我的PHP网页.所以我添加了以下代码:

I want to run my PHP web pages on an apache web server without the .php extension. So I added the following code:

RewriteEngine on
RewriteBase /
Rewritecond %{REQUEST_URI} !(^/?.*\..*$) [NC]
RewriteRule (.*)$ $1.php [NC]

.htaccess 文件中的

.这解决了我的问题,但是又出现了另一个问题.我无法查看任何目录的内容(即目录中包含的文件).请为我提供另一个 RewriteRule ,而不会出现此问题.

in the .htaccess file. This solves my problem but another problem arises. I cannot view the content of any directory (i.e. the file contained in the directory). Please provide me an alternate RewriteRule without this problem.

推荐答案

如果将.php附加到现有资源,则需要确保请求URI指向现有资源:

You need to make sure that the request URI points to an existing resource if you append the.php to the end of it:

RewriteEngine on
RewriteBase /
Rewritecond %{REQUEST_URI} !(^/?.*\..*$) [NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.*)$ $1.php [NC]

RewriteCond%{REQUEST_FILENAME} .php -f 行检查是否在请求的URI后面附加了".php",它映射到现有文件( -f ).

the line RewriteCond %{REQUEST_FILENAME}.php -f checks if a ".php" is appended to the requested URI, it mapes to an existing file (-f).

这篇关于运行没有扩展名的PHP页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆