2009-12-08 64 views
1

这是我的目录结构的.htaccess多重定向

/home 
    /template 
    /classifieds 
    /listings 

我想隐藏/模板,并想展示下在回家的模板中的所有文件。像/home/template/home.php应该是www.example.com/home.php或/home/template/style.css应该是www.example.com/style.css

而有人试图访问示例.com/template/.php应该返回example.com/ .php(如果它存在)或404.php(如果它不存在)。

这是我的htaccess来处理。

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_FILENAME} -f 
RewriteCond %{REQUEST_URI} ^/template/.*php 
RewriteRule . /$1 [NC,R] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

Options -Indexes 

而且我的PHP代码

if (!file_exists("template/" . $page)) 
    include_once "template/404.php"; 
else 
    include_once "template/" . $page; 

然而 我加入了更多喜欢的东西/分类和/列表应被列为是,即example.com/classified/*.php

现在,当我尝试访问/answers/home.php时,它直接打开home.php而不是打开index.php

这是我的新代码

if (!file_exists($segments[1] . '/' . $page)) 
     include_once "template/404.php"; 
else 
    include_once $segments[1] . '/' . $page; 

SO应该是什么样的htaccess?

回答

1

我知道这不是对你的问题的直接回答,但它似乎更合理的逻辑组织您的文件结构以匹配您的网络结构。我会建议:

/home 
    /public_html 
    /classifieds 
    /listings 
    404.php 
    index.php 

从我可以告诉你的帖子,绝对没有理由使用mod_rewrite。

但是,如果你真的想知道:

RewriteCond %{REQUEST_URI} !^/classifieds/ 
RewriteCond %{REQUEST_URI} !^/listings/ 
+0

我第二的“重新组织你的目录”的一部分。 – Don 2009-12-08 06:55:22