2016-12-18 77 views
0

在升級到PHP 7.0.0後,我無法在WAMP上正常運行mod_rewrite。 Apache似乎完全忽略了所有RewriteRule。他們導致404錯誤。WAMP忽略.htaccess中的重寫規則

這是我的虛擬主機httpd-vhosts.conf

<VirtualHost *:80> 
    ServerName myproject.local 
    DocumentRoot "D:/Projects/myproject/www" 
    ErrorLog "D:/Projects/myproject/www/apache_errors.log" 
    LogLevel info 

    <Directory "D:/Projects/myproject/www/"> 
     LogLevel debug 
     Options +Indexes +Includes +FollowSymLinks +MultiViews 
     AllowOverride All 
     Require all granted 
    </Directory> 
</VirtualHost> 

這是我的.htaccess,這是由Apache的認可,將處理像DirectoryIndex指令,但似乎忽略任何RewriteRule S:

RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([a-zA-Z_\-\s]+)/?$ $1.php [L,QSA] #root pages 
RewriteRule ^([a-zA-Z_\-\s]+)/([a-zA-Z_\-\s]+)/?$ core/modules/$1/$2.php [L,QSA] #pages with no id 
RewriteRule ^([a-zA-Z_\-\s]+)/([a-zA-Z_\-\s]+)/([0-9]+)/?$ core/modules/$1/$2.php?$1_id=$3 [L,QSA] #pages with id (edit, etc) 

我的apache錯誤日誌沒有顯示任何結果:只是要求失敗:

[Sun Dec 18 15:47:03.787934 2016] [core:info] [pid 12532:tid 1140] [client ::1:57506] AH00128: File does not exist: D:/Projects/StoryTracker-Core/www/test 

必須有一些外力,我不知道導致這些結果。

<VirtualHost *:80> 
    ServerName myproject.local 
    DocumentRoot "d:/projects/myproject/www" 
    ErrorLog "d:/projects/myproject/www/apache_errors.log" 
    LogLevel trace8 

    <Directory "d:/projects/myproject/www/"> 
     Options +Indexes +FollowSymLinks +Includes 

     AllowOverride All 
     Require all granted 

     LogLevel trace8    
    </Directory> 
</VirtualHost> 
+1

如果禁用「MultiViews」,會發生什麼情況?它通常與重寫相沖突。您應該在這些規則中使用'END'而不是'L',或者添加'DPI'。爲'mod_rewrite'啓用跟蹤。 – Walf

+0

@Walf當我試圖訪問/聯繫/時,我收到了這個唯一的消息。重寫引擎從不會提取並重寫請求。 '[Mon Dec 19 22:36:52.661022 2016] [rewrite:trace1] [pid 8204:tid 1116] mod_rewrite.c(477):[client :: 1:55336] :: 1 - - [myproject.local/sid #1fd26638ca0] [rid#1fd291c9dd0/initial] [perdir D:/ Projects/myproject/www /]通過D:/ Projects/myproject/www/contact' –

+0

我應該得到一個'init rewrite engine with requested uri' then'向uri'/ contact /''應用模式'^([a-zA-Z _ \\ - \\ s] +)/?$',但我不知道爲什麼'init rewrite engine'永遠不會觸發 –

回答

1

mod_rewrite不喜歡在我的項目目錄名破折號:

編輯 如下無濟於事我已經更新了我的虛擬主機。

在將我的項目路徑中的目錄重新命名爲使用-之後,我能夠從LogLevel debug rewrite:trace8找出其餘問題。

+1

將'-'加回路徑立即破解它?或者你知道哪些步驟觸發它?如果是這樣,你應該提交一份最小代碼的錯誤報告以使其可重現。 – Walf