运行没有扩展名的PHP页面 [英] Run PHP pages without an extension
问题描述
我想在没有 .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屋!