使用.htaccess文件隐藏路径中的文件夹

时间:2017-03-15 15:35:01

标签: apache .htaccess mod-rewrite

我希望在网址路径http://example.com/contents/folder-1/中隐藏名为contents的文件夹

我的文件夹结构如下:

/
--contents/
----folder-1/
------index.php
----folder-2/
------index.php
----folder-3/
------index.php
index.php 

我拥有对服务器的完全root权限,启用了a2enmod重写,重启了apache。然后我将以下.htaccess文件放在/目录中。

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+contents/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^contents/)^(.*)$ /contents/$1 [L,NC]

但是,当我转到http://example.com/folder-1/时,它只会给我404页错误。

0 个答案:

没有答案
相关问题