??今天遇到一個網(wǎng)站報錯“抱歉~~~服務器運行腳本錯誤”,如下圖:
一開始認為是環(huán)境問題,重新加載環(huán)境以后故障依舊,然后開始排查偽靜態(tài)文件,把.htaccess重命名以后的確可以訪問,但是網(wǎng)站內(nèi)頁404錯誤。于是開始檢查偽靜態(tài)規(guī)則,規(guī)則如下:
RewriteEngine on RewriteBase / DirectoryIndex web/index.php RewriteRule haoshentuochangjia/$ web/company.php?id=1 RewriteRule haoshentuochanpin/$ web/products.php?id=2 RewriteRule xinkuanhaoshentuo/$ web/products.php?id=3 RewriteRule haoshentuotuobazixun/$ web/news.php?id=4 RewriteRule haoshentuoshipin/$ web/company.php?id=2 RewriteRule sitemap.html/ web/sitemap.php RewriteRule ([a-z]+).html$ web/$1.php
由于此網(wǎng)站結構較復雜,和我們一般的網(wǎng)站都不同,他網(wǎng)站程序是放在的根目錄的二級目錄里,然后通過偽靜態(tài)指定首頁文件路徑跳轉訪問。
刪除首頁跳轉規(guī)則(DirectoryIndex web/index.php)以后域名+目錄可以訪問,但是直接訪問域名無法跳轉,由于服務器還有一個網(wǎng)站和這個網(wǎng)站使用的同樣的程序訪問正常,所以排除了服務器原因。于是去查看了網(wǎng)站的報錯日志,分析懷疑是網(wǎng)站的配置文件偽靜態(tài)配置有問題,把兩個配置文件下載到本地的確發(fā)現(xiàn)第11行不同(相同的代碼我省略了未貼出),把AllowOverride AuthConfig FileInfo更改為AllowOverride All更改以后測試訪問正常,下圖:
<VirtualHost *:80> …… AddHandler php5-cgi .php Action php5-cgi /php5-cgi AllowOverride AuthConfig FileInfo //此處不同 Options -Indexes -ExecCGI Includes IncludesNOEXEC FollowSymLinks Allow from all </Directory> …… </VirtualHost>
<VirtualHost *:80> …… AddHandler php5-cgi .php Action php5-cgi /php5-cgi AllowOverride All //正常 Options -Indexes -ExecCGI Includes IncludesNOEXEC FollowSymLinks Allow from all </Directory> …… </VirtualHost>
百度搜索得出結論:在 AllowOverride 設置為 None 時, .htaccess 文件將被完全忽略。當此指令設置為 All 時,所有具有 ".htaccess" 作用域的指令都允許出現(xiàn)在 .htaccess 文件中,大多數(shù)情況下用AllowOverride All即可。
2016年1月4日 下午12:15 沙發(fā)
同意博主的觀點,贊一個!