PHP CodeIgniter(如何制作公用文件夹)

时间:2014-03-10 14:00:19

标签: php .htaccess codeigniter

我是CodeIgniter的新手。

我创建了公共文件夹,我想放置我的css / js / images文件夹。

我的设置就是这样:

application
   cache
   config
   controllers
   public
       css
       js
       images
  ....
  ....
  ....

我的.htaccess是:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /moviesmvc/

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

    </IfModule>

    <IfModule !mod_rewrite.c>
        # If we don't have mod_rewrite installed, all 404's
        # can be sent to index.php, and everything works as normal.
        # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule> 

如何公开此公用文件夹?

/////////////////////////

4 个答案:

答案 0 :(得分:1)

确实不希望将公用文件夹放在应用程序文件夹中。您的目录结构应该是这样的

 -- application
 -- system
 -- public
    -- css
    -- js
    -- images
    -- index.php
    -- .htaccess

这是最佳实践,您将来会为自己节省大量时间和潜在的问题

答案 1 :(得分:0)

如果它是Linux服务器,那么您需要将文件夹权限更改为755或777.请为此安装Google,您将获得更多详细信息。

我建议不要在分钟使用CI,因为它们在找到新的所有者之前不再开发。相反,我会推荐Laravel,因为它是一个非常棒的框架,但你也应该尝试使用CakePHP,Symfony,Yii或其他仍在开发中的东西。

答案 2 :(得分:0)

检查您的公用文件夹权限以及使用base_url()函数获取公共网址..

例如

echo base_url('public/images'); to get image public path

答案 3 :(得分:0)

我不建议实施这种类型的设计,原因如下:

  • Web服务器旨在不允许在文档根目录下进行公共访问。这有助于简化设置和安全性。

  • 如果在根目录中进行了重大安全更改,则必须将其复制到公用文件夹中。

  • 您正在向Web服务器的 EVERY HTTP / HTTPS调用添加不必要的处理,因为现在必须为每个请求处理规则。如果您可以将其构建到httpd.conf文件中,那么开销几乎不存在。

<强> TL; DR;

无需通过在周边添加一个块来重新发明轮子。

相关问题