使用.htacces启用目录

时间:2016-06-06 22:33:35

标签: .htaccess

我有以下.htaccess配置:

RewriteEngine on
RewriteBase /
RewriteRule ^model/([^/\.]+)/?$ /model/index.php?u=$1 [L,NC,QSA]
RewriteRule ^collections/([^/\.]+)/?$ /collections/index.php?c=$1 [L,NC,QSA]
RewriteRule ^general/([^/\.]+)/?$ /general/index.php?p=$1 [L,NC,QSA]
RewriteRule ^blog/([^/\.]+)/?$ /blog/index.php?e=$1 [L,NC,QSA]
RewriteRule ^blog/archive/ /blog/archive/index.php [L,NC,QSA]

我需要的只是启用http://example.org/blog/archive/ url,现在在这样的目录中有一个index.php文件。

问题是上面的规则/博客/采取行动而不是最后一个。

我该怎么办?

1 个答案:

答案 0 :(得分:0)

更改规则的顺序:

RewriteEngine on
RewriteBase /

RewriteRule ^model/([^/.]+)/?$ /model/index.php?u=$1 [L,NC,QSA]
RewriteRule ^collections/([^/.]+)/?$ /collections/index.php?c=$1 [L,NC,QSA]
RewriteRule ^general/([^/.]+)/?$ /general/index.php?p=$1 [L,NC,QSA]
RewriteRule ^blog/archive/ /blog/archive/index.php [L,NC,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/([^/.]+)/?$ /blog/index.php?e=$1 [L,NC,QSA]

但是,如果/blog/archive/是真实目录,那么如果您在.htaccess上添加此行,则甚至不需要任何重写规则:

DirectoryIndex index.php

默认情况下,这将为任何目录加载index.php

相关问题