在升級到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>
如果禁用「MultiViews」,會發生什麼情況?它通常與重寫相沖突。您應該在這些規則中使用'END'而不是'L',或者添加'DPI'。爲'mod_rewrite'啓用跟蹤。 – Walf
@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' –
我應該得到一個'init rewrite engine with requested uri' then'向uri'/ contact /''應用模式'^([a-zA-Z _ \\ - \\ s] +)/?$',但我不知道爲什麼'init rewrite engine'永遠不會觸發 –