2017-02-22 37 views
0

我試圖重定向到包含index.php等的/ hc /目錄。瀏覽器顯示ERR_TOO_MANY_REDIRECTS錯誤。請告訴我我在這裏做錯了什麼。Laravel 5.X - 使用IP地址時出現太多重定向錯誤

這是工作得很好,當我在我的舊主機中使用域名。現在,當我使用IP時,它失敗了。

# Turn on URL rewriting 
RewriteEngine On 

# Installation directory 
RewriteBase /hc/ 

# Protect hidden files from being viewed 
<Files .*> 
Order Deny,Allow 
Deny From All 
</Files> 

RewriteCond %{HTTP_HOST} ^45.117.122.107$ [NC] 
RewriteRule ^(.*)$ http://45.117.122.107/$1 [L,R=301] 

# Protect application and system files from being viewed 
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L] 

# Allow any files or directories that exist to be displayed directly 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# Rewrite all other URLs to index.php/URL 
RewriteRule .* index.php?/$0 [PT,L,QSA] 
+0

回退我的變化,如果你不喜歡他們。 –

回答

0

這一規則

RewriteCond %{HTTP_HOST} ^45.117.122.107$ [NC] 
RewriteRule ^(.*)$ http://45.117.122.107/$1 [L,R=301] 

的問題是,它重定向^(.*)$本身$1。然後,客戶端再次請求相同的URL,並重定向到自己,並再次請求相同的URL,等等......使用域名不會改變這一點。

要避免此重定向循環或任何其他循環,您需要一些條件,它可以提前退出或跳過此規則。


凡事重定向到/hc,您可以使用此規則

RewriteRule !^hc/ /hc%{REQUEST_URI} [R,L] 

這個規則首先檢查,如果該請求是不是已經爲hc,如果不將它重定向。

然後爲/hc/每個請求改寫爲index.php

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule^index.php?/%{REQUEST_URI} [L] 
+0

你能否告訴我一個解決方法? – logeeks

+0

這取決於規則應該做什麼。就目前而言,這條規則實際上什麼都不做,你可以將其刪除。 –

+0

謝謝,我在public_html文件夾中有一個laravel'/ hc'目錄,我需要將每個請求重定向到'hc'目錄,而hc目錄又會調用相應的控制器。它似乎不適合我。我已經指出了線條,但它仍然不適合我。 – logeeks