2011-01-05 39 views
2

我的文件夾結構:mod_rewrite的 - 防止多重定向

現在我有,在某些情況下,我的Apache重寫往往內部,我得到一個500服務器錯誤的問題,這裏的日誌:

[Wed Jan 05 17:51:54 2011] [error] [client 127.0.0.1] Request exceeded the limit of 3 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. 
[Wed Jan 05 17:51:54 2011] [debug] core.c(3046): [client 127.0.0.1] r->uri = /nameoftherootfolder/public/index.php 
[Wed Jan 05 17:51:54 2011] [debug] core.c(3052): [client 127.0.0.1] redirected from r->uri = /nameoftherootfolder/public/index.php 
[Wed Jan 05 17:51:54 2011] [debug] core.c(3052): [client 127.0.0.1] redirected from r->uri = /nameoftherootfolder/public/index.php 
[Wed Jan 05 17:51:54 2011] [debug] core.c(3052): [client 127.0.0.1] redirected from r->uri = /nameoftherootfolder/nothere/ 

我的.htaccess:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^.*$ index.php [NC,L] 

在index.php處理所有要求,如果協調官還處理ssed網址錯誤,例如不存在。

它的工作原理是如果訪問的url存在,但它的URL是「錯誤的」我得到這個錯誤。 我得到這個只是因爲我設置一個Apache別名:

Alias /nameoftherootfolder/ "C:/somepathshere/WAMP/www/nameoftherootfolder/public/" 

<Directory "C:/somepathshere/WAMP/www/nameoftherootfolder/public/"> 
    Options Indexes FollowSymLinks MultiViews 
    AllowOverride all 
     Order allow,deny 
    Allow from all 
</Directory> 

如何我現在可以防止過多的內部重定向與Apache?有沒有RewriteCond? 我使用的是Apache 2.2.11。

編輯:

如果我把一個index.php/它的工作URI內,但是這是SEO不友好,對用戶不夠友好,看起來可怕,例如請求。 http://localhost/nameoftherootfolder/index.php/nothere/http://localhost/nameoftherootfolder/index.php/index/

編輯#2:我添加

RewriteBase /nameoftherootfolder/ 

後,它的工作原理就知道了。

回答

6

後,我加入

RewriteBase /nameoftherootfolder/ 

現在的工作。

1

您需要排除對index.php本身的呼叫以防止無限循環。

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-s 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !^/index\.php$ 
RewriteRule ^.*$ index.php [NC,L] 
+0

嗯......它似乎沒有影響...仍在apache錯誤日誌中得到相同的錯誤。 – Poru 2011-01-05 17:28:38

+0

@Poru嘗試更新的版本,它是一個完整的htaccess文件 – 2011-01-05 17:35:50

+0

我試過了,結果相同...也許這是別名的問題?順便說一句。看看上面的編輯。 – Poru 2011-01-05 17:37:45

0

在我的情況下,我在Apache中配置的另一個站點的文件夾下的子域上有一個站點。這固定我的重寫錯誤:

RewriteBase/