歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Apache的htaccess文件出現500錯誤的原因

Apache的htaccess文件出現500錯誤的原因

日期:2017/3/1 12:18:31   编辑:關於Linux

Apache 我平時很少用到,今天測試環境下碰到個問題,老是500錯誤莫名其妙

Apache的htaccess文件出現500錯誤的原因

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^m/(.*)$ m.php/$1 [L]
  RewriteRule ^(.*)$ index.php/$1 [L]

一開始這麼些,感覺應該是正常的邏輯吧,m/ 開頭的都到 m.php 去然後終止,其他為匹配到 m 的則去 index.php,結果發現直接500錯誤,崩潰怎麼改都不行。

然後郁悶的查看日志發現提示貌似重寫進入死循環了。。。很是奇怪,感覺應該是規則的正則范圍有問題

AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use ‘LimitInternalRecursion’ to increase the limit if necessary. Use ‘LogLevel debug’ to get a backtrace.

換了個新寫法

  RewriteCond %{REQUEST_URI} ^/m/
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^m/(.*)$ m.php/$1 [L]

  RewriteCond %{REQUEST_URI} !^/m/
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php/$1 [L]

Apache的htaccess文件出現500錯誤的原因<喎?http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4NCjxwPjxjb2RlIGNsYXNzPQ=="hljs apache">分成了兩部分,增加個 URI 的匹配條件,明確分為兩種條件,
即:
1. 以 /m/ 開頭
2. 不是以 /m/ 開頭的

這樣明確正則范圍終於ok了,

結論,貌似 Apache 的 RewriteRule 中的正則規則是不能存在一條包含另一條的情況,必須每個規則明確,否則就會出現死循環或者正則遞歸過大的情況導致500錯誤

附一個apache 規則轉換到 nginx 的工具地址:
http://www.anilcetin.com/convert-apache-htaccess-to-nginx/

Copyright © Linux教程網 All Rights Reserved