apache2 httpd配置

时间:2012-03-08 01:18:19

标签: apache

我的文档根目录是/ var / www,我没有启用虚拟主机。 这是我的文件夹结构/ var / www:

index.php
classes (external)
controllers
models
files (img, js, css)
views (pages, components)

如您所见,我正在使用模型视图控制器模式。我现在需要的是我必须在我的httpd.conf中使用的正确配置,以定义只有文件夹可以被接收而没有其他文件夹,以防止“未找到”消息或直接php访问。我该怎么设置呢?

这是我目前的httpd.conf

ServerSignature Off
ServerTokens Full

# Settings for server @ port 80.
<VirtualHost *:80>
    ServerName <url>
    DocumentRoot /var/www
    DirectoryIndex index.php

    # No one has access to the main directory.
    <Directory />
        Order Deny,Allow
        Deny from all
        Options None
        AllowOverride None
    </Directory>

    # Configure the main directory
    <Directory /var/www>

        # Everyone has access to the main directory.
        Order Allow,Deny
        Allow from all
        Options FollowSymLinks
        AllowOverride None

        # Enable clean urls.
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php/$1 [L]
    </Directory>
</VirtualHost>

感谢您的帮助:)

1 个答案:

答案 0 :(得分:1)

如果可能的话,最好将控制器,查看脚本和其他与应用程序相关的代码保留在/var/www之外,而不是将其放在/var/application或类似内容中。

然后,您不需要任何重写规则来拒绝访问除文件之外的所有内容。如果您想要添加对新文件夹的访问权限(例如/var/www/css),那么您可能需要做一些事情才能使其可访问。或者你有相反的情况,你明确拒绝你不想访问的文件夹。这样做但是如果.htaccess被破坏或有人忘记将规则转移到新服务器那么你还有更多工作要做。

index.php中,定义一些常量来说明文件的存在位置(例如define('APPLICATION_PATH', '/var/application');

相关问题