[英]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.