【发布时间】:2014-11-27 17:25:36
【问题描述】:
我在 apache2 服务器上工作。我正在尝试使用以下 .htaccess 文件在我的网站上显示没有文件扩展名 .php 的网页:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
# 1 ---- Establish a custom 404 File not Found page ----
ErrorDocument 404 /filenotfound.php
# 2 ---- Prevent directory file listing in all of your folders ----
IndexIgnore *
它根本不起作用。我仍然在浏览器中看到带有 .php 扩展名的网页。
我已经加载了 mod rewrite 模块,并且我在 apache2.conf 文件中进行了如下更改:
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
我的 .htaccess 文件也在做其他工作(即将 404 重定向到 filenotfound.php )没有任何问题。那么为什么这个重写规则不起作用呢?我怎样才能调试 .htaccess 文件?
【问题讨论】:
-
调试您的 htaccess 使用:htaccess.madewithlove.be 编辑,啊请求文件名不支持 atm - 但用于一般调试问题的好工具。