[英]PHP CodeIgniter (how to make public folder)
我是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>
如何使该公用文件夹公开?
/////////////////////////
您确实不想将公用文件夹放在应用程序文件夹中。 您的目录结构应如下所示
-- application
-- system
-- public
-- css
-- js
-- images
-- index.php
-- .htaccess
这是可以遵循的最佳做法,将来您可以节省很多时间和潜在的问题
如果是Linux服务器,则需要将文件夹权限更改为755或777。为此,请使用Google,您将获得更多详细信息。
我建议您暂时不要使用CI,因为在找到新所有者之前,不会再开发CI。 相反,我会推荐Laravel,因为它是一个了不起的框架,但是您还应该尝试CakePHP,Symfony,Yii或其他仍在开发中的东西。
检查您的公用文件夹权限,并使用base_url()函数获取公用URL。
例如
echo base_url('public/images'); to get image public path
我不建议实施这种设计,这是为什么:
Web服务器被设计为不允许在文档根目录下进行公共访问。 这有助于易于设置和安全。
如果在根目录中进行了重大的安全更改,则必须将其复制到您的公用文件夹中。
您正在向对Web服务器的每个 HTTP / HTTPS调用添加不必要的处理,因为现在必须为每个请求处理规则。 如果您可以将其构建到httpd.conf
文件中,那么开销几乎不存在。
TL; DR;
无需通过在周长周围添加块来重新发明轮子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.