简体   繁体   English

PHP CodeIgniter(如何设置公用文件夹)

[英]PHP CodeIgniter (how to make public folder)

I'm a new in CodeIgniter. 我是CodeIgniter的新手。

I made public folder, where I want to put my css/js/images folders. 我创建了公用文件夹,我想在其中放置css / js / images文件夹。

My setup is like that: 我的设置是这样的:

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

My .htaccess is: 我的.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> 

how can I make this public folder public? 如何使该公用文件夹公开?

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

You really don't want to put your public folder inside your application folder. 确实不想将公用文件夹放在应用程序文件夹中。 Your directory structure should be like this 您的目录结构应如下所示

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

This is the best practice to follow and you will save yourself a lot of time and potential problems in the future 这是可以遵循的最佳做法,将来您可以节省很多时间和潜在的问题

If it's a Linux server then you need to change the folder permissions to 755 or 777. Have a Google around for this and you will get a lot more detail. 如果是Linux服务器,则需要将文件夹权限更改为755或777。为此,请使用Google,您将获得更多详细信息。

I would recommend not using CI at the minute as it isn't being developed on any more until they find a new owner. 我建议您暂时不要使用CI,因为在找到新所有者之前,不会再开发CI。 Instead, I would recommend Laravel as it's such an amazing framework, but you should also try out CakePHP, Symfony, Yii or something else which is still being developed. 相反,我会推荐Laravel,因为它是一个了不起的框架,但是您还应该尝试CakePHP,Symfony,Yii或其他仍在开发中的东西。

Check Your Public Folder Permission as well as use base_url() function to get the public url.. 检查您的公用文件夹权限,并使用base_url()函数获取公用URL。

for example 例如

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

I would not advise to implement this type of design and here is why: 我不建议实施这种设计,这是为什么:

  • Web servers are designed to not allow public access below the document root. Web服务器被设计为不允许在文档根目录下进行公共访问。 This aides in both ease-of-setup and security. 这有助于易于设置和安全。

  • If a major security change is made within the root then it has to be duplicated to your public folder. 如果在根目录中进行了重大的安全更改,则必须将其复制到您的公用文件夹中。

  • You are adding unnecessary processing to EVERY HTTP/HTTPS call to your web server because now the rules have to be processed for every request. 您正在向对Web服务器的每个 HTTP / HTTPS调用添加不必要的处理,因为现在必须为每个请求处理规则。 If you could build this into your httpd.conf file instead then the overhead is nearly non-existent. 如果您可以将其构建到httpd.conf文件中,那么开销几乎不存在。

TL;DR; TL; DR;

No need to re-invent the wheel by adding a lump around the perimeter. 无需通过在周长周围添加块来重新发明轮子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM