2017-01-07 85 views
1

我最近將我的index.php(處理路由的文件)和css/js/font資產移動到public/文件夾中。出於安全考慮,我只希望此public/文件夾中的項目可訪問。當我意識到我可以訪問mysite.com/composer.lock並查看與我的舊.htaccess和文件夾設置的作曲鎖文件時,我遇到了這個問題。MVC公用文件夾htaccess不工作

這是我想

如果我訪問mysite.com/car/create,我希望它實際指向mysite.com/public/index.php?path=car/create

如果我鏈接到資產,如mysite.com/css/style.css,我希望它真正指向mysite.com/public/css/style.css

這裏是我的文件夾結構

MVC Folder Structure

這裏是我的.htaccess這是不是在所有

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.+)$ public/index.php?path=$1 [L,QSA] 
</IfModule> 

工作我不知道如何解決這個問題。它只是生成空白頁面,我仍然可以直接訪問根目錄中的文件等任何幫助表示讚賞。

回答

1

您現有的指令專門避免重寫現有文件的請求,所以它仍然使您能夠訪問根目錄中的文件。它也將重寫靜態資源到public/index.php?path=,這可能會失敗。

嘗試,而不是執行以下操作:

RewriteEngine On 

# Stop processing if already in the /public directory 
RewriteRule ^public/ - [L] 

# Static resources if they exist 
RewriteCond %{DOCUMENT_ROOT}/public/$1 -f 
RewriteRule (.+) public/$1 [L] 

# Route all other requests 
RewriteRule (.*) public/index.php?path=$1 [L,QSA]