htaccess删除文件扩展名并允许同名文件夹

时间:2015-06-27 07:56:31

标签: php regex apache .htaccess mod-rewrite

我的网站上有一个链接

  

x.icebreaker.com/products

和目录中的文件

  

x.icebreaker.com/products/bow

我有以下.htaccess文件,允许在浏览器中删除文件扩展名,但是当有一个同名文件夹时,我无法显示页面(默认打开文件夹

  

x.icebreaker.com/products /

我该如何解决这个问题?

ErrorDocument 404 /404.php
ErrorDocument 403 /403.php

# Disable directory browsing
Options All -Indexes

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)/?$ $1.php

如果不清楚问题不在于如何让页面加载x.icebreaker.com/products,那么如何获取 NOT 来加载x.icebreaker.com/products/

1 个答案:

答案 0 :(得分:2)

您还需要禁用MultiViews选项:

Options All -Indexes -MultiViews

MultiViews使用选项Apache's content negotiation modulemod_rewrite之前运行,并使Apache服务器匹配文件扩展名。因此/file可以在网址中,但它会投放/file.php

同时使用此规则替换.php添加规则:

RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]