2016-10-06 36 views
1

所有請求,因此,這裏是我的文件夾結構是這樣的:如何重定向與的.htaccess

/ 
    /public/ 
    /index.php 
    /app/ 
.htaccess 

我想,當我鍵入www.example.com請求轉到public\index.php文件,但不顯示public。 如果我去www.example.com\app它去\public\app但只顯示www.example.com\app

使用.htaccess可以嗎?

回答

2

在站點根目錄的.htaccess您可以使用此:

DirectoryIndex index.php 
RewriteEngine On 

# add trailing slash in front of directories 
RewriteCond %{DOCUMENT_ROOT}/public/$1 -d 
RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L,R=301,NE] 

# internally forward to /public/... 
RewriteRule !^public/ public%{REQUEST_URI} [L,NC] 
+0

但有了這個,當我去'www.example.com/app'它但在地址欄中顯示「www.example.com/public/app」。我怎樣才能隱藏「公共」? – MrMadBacon

+0

徹底清除瀏覽器緩存後嘗試更新我的規則。 – anubhava

+1

謝謝!它像一個魅力! – MrMadBacon

0

這應該工作:

RewriteRule ^$ /public/index.php [L] 

RewriteCond %{REQUEST_URI} !^/public [NC] 
RewriteRule ^(.*)$ public/$1 [L]