2015-09-17 37 views
2

由於我是laravel的新手,我已經安裝了一個全新的副本,給予必要的權限並運行應用程序,一切都很好。 現在我有創建的Apache虛擬主機去除公衆,這也是工作的罰款:從Laravel 5中刪除public和index.php的最佳方法URLS

<VirtualHost *:80> 
ServerName mobileapp 

ServerAdmin [email protected] 
DocumentRoot /var/www/html/mobileapp/public 
<Directory "/var/www/html/mobileapp/"> 
    Options FollowSymLinks 
    AllowOverride All 
    Order allow,deny 
    Allow from all 
</Directory> 

ErrorLog ${APACHE_LOG_DIR}/mobileapp_error.log 
CustomLog ${APACHE_LOG_DIR}/mobileapp_access.log combined 

現在,該網站可以在本地通過http://mobileapp/index.php/pages訪問,但如果我從鏈接中刪除的index.php(不工作http://mobileapp/pages)。 我的.htaccess文件是:

<IfModule mod_rewrite.c> 
<IfModule mod_negotiation.c> 
    Options -MultiViews 
</IfModule> 

RewriteEngine On 

# Redirect Trailing Slashes If Not A Folder... 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)/$ /$1 [L,R=301] 

# Handle Front Controller... 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
#RewriteRule^index.php [L]   # <----- Tested not working 
RewriteRule ^(.*)$ /$1 [L]    # <----- neither this one 

我也能mode_rewrite。任何人都可以告訴我什麼是最好的和簡單的方法來騎這個。

回答

2

試試這個前端控制器規則:

RewriteRule ^index\.php(/|$) - [L,NC] 

# Handle Front Controller... 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^.]+)/?$ index.php/$1 [L] 
+0

它在日誌文件中給出此錯誤:由於可能的配置錯誤,請求超出了10個內部重定向的限制 –

+0

好的檢查更新的答案和更新你的問題,如果你更多的規則在你的htaccess – anubhava

+1

是啊,它現在工作正常..謝謝。其實我已經將兩個.htaccess文件放在根目錄中,而另一個放在公共目錄中。現在我刪除根目錄(因爲DocumentRoot是公共目錄),然後將.htaccess更改爲舊目錄,工作正常......但是,您也可以在最壞的情況下工作,謝謝... :) –

1

要調試重寫,以下內容添加到您的.htaccess

RewriteLog ${APACHE_LOG_DIR}/rewrite.log 
RewriteLogLevel 9 

那麼你可以嘗試不同的正則表達式爲你的RewriteRules看個究竟。我會嘗試像下面這樣:

RewriteRule ^/index.php(.*)$ http://mobileapp/$1 [L] 

記住,對於RewriteRule申請,RewriteCond線需要首先滿足。在你的情況,你正在做的條件!-d!-f,所以這可能是你的問題。

+0

它給了我在日誌文件中此錯誤:無效的命令「RewriteLog」,或許是一個拼寫錯誤或定義模塊不包含在服務器配置中 –

+0

奇怪的是,它帶有mod_rewrite:http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritelog – xxfelixxx

+0

但是,這已被替換爲另一種機制在Apache 2.4:http ://httpd.apache.org/docs/current/mod/mod_rewrite.html#logging所以你只需要設置LogLevel – xxfelixxx

0

我只是重新命名server.phpindex.php和它的作品