【发布时间】:2010-09-24 10:54:41
【问题描述】:
我正在更新一个 php 应用程序,该应用程序目前不使用 url 重写。目的是隐藏文件扩展名。网站的大体结构如下
root/
index.php
login.php
page1.php
page2.php
page3.php
page4.php
page5.php
page6.php
page7.php
page8.php
subfolder/
index.php
validpage.php
images/
css/
上述结构中的子文件夹是唯一的,它是唯一包含php文件的子文件夹。所有其他文件都在根文件夹中。
Mod Rewrite and PHP和Mod-Rewrite or PHP router?和mod_rewrite, php and the .htaccess file这些问题我都经历过
更新 htaccess。感谢@thomasmalt
RewriteEngine on
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -l
RewriteRule ^.*$ - [NC,L]
# only rewrite if the requested file doesn't exist
RewriteCond %{REQUEST_FILENAME} !-s
# add .php to the url
RewriteRule ^(.*)$ $1.php
现在的问题是,当我尝试访问不存在的页面(如 localhost/inex.php)时,我得到的是 500 而不是 404 错误。 Apache 错误日志 给了我以下错误。 (我访问了 localhost/index ,它加载了 index.php 的内容,然后我加载了 localhost/inex ,这给了我一个 500 错误。)
[Sat Sep 25 14:44:26 2010] [error] [client 127.0.0.1] File does not exist: C:/wamp/www/index
[Sat Sep 25 14:44:36 2010] [error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
更新:找到了我的问题here 的答案。问题解决了。
【问题讨论】:
-
很难从帖子中了解您想要实现的目标,而且太长了。您应该考虑重写它以澄清。
-
@thomasmalt:我重写了重写问题
标签: php .htaccess mod-rewrite