Я пытаюсь понять, почему мой .htaccess не учитывается при загрузке файла .php. Ниже файлы находятся в корневом каталоге моего локального хоста.
.htaccess
# Cause a HTTP 500
test
file.html
<html><body><h1>This should not show</h1></body></html>
file.php
<html><body><h1>This should not show</h1></body></html>
когда я открываю /index.html, я получаю ожидаемый HTTP500 Когда я открываю /index.php, отображается html.
Есть идеи, почему .htaccess не загружается для файла PHP?
Apache 2.4.6 VHost (/etc/httpd/vhosts.d/website.local.conf):
<VirtualHost *:443>
ServerName website.local
ServerAlias www.website.local
DocumentRoot /var/www/vhosts/website/website
<Directory /var/www/vhosts/website/website>
require all granted
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
# Trigger PHP-FPM to run PHP execution
<IfModule proxy_fcgi_module>
ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/www/vhosts/website/php-fpm.sock|fcgi://website/var/www/vhosts/website/website"
DirectoryIndex index.php
</IfModule>
SSLEngine on
SSLCertificateKeyFile /var/www/ssl/website.key
SSLCertificateFile /var/www/ssl/website.crt
</VirtualHost>
Для этого сайта нет других конфигураций vhost:
[root@localhost ~]# cat /etc/httpd/conf/*.conf | grep website.local
[root@localhost ~]# cat /etc/httpd/vhosts.d/*.conf | grep website.local
ServerName website.local
ServerAlias www.website.local
[root@localhost ~]#
Обновление 1:
Я включил перезапись: trace3 loglevel после. Инструкции по отладке htaccess из https://stackoverflow.com/questions/5641618/how-to-enable-loglevel-debug-on-apache2-server . Похоже, что файл .htaccess даже не рассматривается Apache при загрузке файла PHP:
Доступ к "/file.html" - .HTAccess загружается, и HTTP500 возвращается, как ожидалось
==> /var/log/httpd/website-error_log <==
[Thu Jul 07 09:36:02.651091 2016] [core:alert] [pid 2822] [client 10.128.3.189:56406] /var/www/vhosts/website/website/.htaccess: Invalid command 'test', perhaps misspelled or defined by a module not included in the server configuration
==> /var/log/httpd/website-access_log <==
10.128.3.189 - - [07/Jul/2016:09:36:02 +0100] "GET /wp-admin/ HTTP/1.1" 500 527 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0"
Доступ к "file.php" -. HTAccess не загружается, и возвращается HTTP200
==> /var/log/httpd/website-access_log <==
10.128.3.189 - - [07/Jul/2016:09:38:41 +0100] "GET /file.php HTTP/1.1" 200 64057 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0"
10.128.3.189 - - [07/Jul/2016:09:38:41 +0100] "GET /file.php?=PHPE9568F34-D428-11d2-A769-00AA001ACF42 HTTP/1.1" 200 2524 "https://www.website.local/file.php" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0"
10.128.3.189 - - [07/Jul/2016:09:38:41 +0100] "GET /file.php?=PHPE9568F35-D428-11d2-A769-00AA001ACF42 HTTP/1.1" 200 2146 "https://www.website.local/file.php" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0"
Доступ к файлу "file.jpg" - .HTAccess загружен, а HTTP500 возвращается, как ожидалось
==> /var/log/httpd/website-error_log <==
[Thu Jul 07 09:43:08.403263 2016] [core:alert] [pid 2827] [client 10.128.3.189:56551] /var/www/vhosts/website/website/.htaccess: Invalid command 'sfdgsaga', perhaps misspelled or defined by a module not included in the server configuration
==> /var/log/httpd/website-access_log <==
10.128.3.189 - - [07/Jul/2016:09:43:08 +0100] "GET /file.jpg HTTP/1.1" 500 527 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0"
Я не знаю ни одной конфигурации, которая запрещала бы .htaccess для определенных типов файлов / пантомимы. Удаление приведенного ниже кода из конфигурации больше не пропускает файлы .htaccess
<IfModule proxy_fcgi_module>
ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/www/vhosts/website/php-fpm.sock|fcgi://website/var/www/vhosts/website/website"
DirectoryIndex index.php
</IfModule>
Обновление 4: Престижность @ w3d за указание на это. Внутреннее проксирование запроса будет пропускать файл .htaccess . Конечно, есть. Я обновил свой файл VHost следующим образом, следуя ответу из этой ветки: Apache 2.4 + PHP-FPM + ProxyPassMatch
<VirtualHost *:443>
ServerName website.local
ServerAlias www.website.local
DocumentRoot /var/www/vhosts/website/website
<Directory /var/www/vhosts/website/website>
require all granted
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
ErrorLog "logs/website-error_log"
CustomLog "logs/website-access_log" combined env=!forwarded
CustomLog "logs/website-access_log" proxy env=forwarded
# Proxy set-up as per
# https://serverfault.com/questions/450628/apache-2-4-php-fpm-proxypassmatch
# This is to forward all PHP to php-fpm.
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/www/vhosts/website/php-fpm.sock|fcgi://website/"
</FilesMatch>
# Set some proxy properties (the string "unique-domain-name-string" should match
# the one set in the FilesMatch directive.
<Proxy fcgi://website>
ProxySet connectiontimeout=5 timeout=240
</Proxy>
DirectoryIndex /index.php index.php
# If the php file doesn't exist, disable the proxy handler.
# This will allow .htaccess rewrite rules to work and
# the client will see the default 404 page of Apache
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f
RewriteRule (.*) - [H=text/html]
SSLEngine on
SSLCertificateKeyFile /var/www/ssl/website.key
SSLCertificateFile /var/www/ssl/website.crt
</VirtualHost>
Престижность @ w3d за указание на это. При внутреннем проксировании запрос пропустит файл .htaccess. Конечно, есть. Я обновил свой файл VHost следующим образом, следуя ответу из этой ветки: Apache 2.4 + PHP-FPM + ProxyPassMatch
חלק זה של תצורת ה- vhosts רלוונטי כאשר אתה ניגש לאתר זה באמצעות https, אתה אמור לקבל מופע נוסף ב- vhosts, האם אתה יכול לחפש שוב ולעדכן את ההודעה שלך?