如何通过 HTTP/2 在 htaccess 中启用 mod_redirect
How to enable mod_redirect in htaccess over HTTP/2
我修改了我的 Debian 9 安装 (Apache 2.4.25) 以允许 HTTP/2 支持。
我已经在线检查成功,页面 确实 服务,但问题在于在 .htaccess 中执行的重定向以映射示例站点。com/index.php/brands/mybrand 到一个不错的 url (site.com/brands/mybrand)。它根本不会发生。这是一个 Codeigniter 设置。
- 有问题的步骤似乎是当我禁用当前模块(
a2dismod php7.2
和 mpm_prefork
)并启用 mpm 模块(a2enmod mpm_event
,但我也尝试过 mpm_worker
) 支持 HTTP/2。
- 那时我得到 "file not found"(404 错误)
- 通过恢复这两个步骤,我恢复正常(当然没有 HTTP/2)
是否通过加载mpm_worker模块使下面的mod_rewrite.c条件无效?如果可以,我该如何更换它?
EDIT: a detailed Log show me this error:
AH01071: Got error 'Primary script unknown\n', referer: https://sitename.com/brands/
我的 .htaccess(在 index.php 所在的 brands 目录中)与之前的配置配合良好:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css|css)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>
IndexOptions +Charset=UTF-8
我的/etc/apache2/sites-enabled/default-ssl.conf相关内容包括:
<VirtualHost _default_:443>
# even without enabling here h2c or h2 I get the error
Protocols http/1.1
<Directory "/var/www/html">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
# since apache 2.4
Require all granted
</Directory>
</VirtualHost>
注意:我之前 运行 启用所需的其他模块的其他命令如下。我不需要触及任何东西就可以恢复到工作(非 HTTP/2)配置:
apt-get install php7.2-fpm
a2enmod proxy_fcgi setenvif
a2enconf php7.2-fpm
编辑:
问题是由内部重定向引起的。现已修复。
您没有正确配置 PHP-FPM。通过说 a2disconf php7.2-fpm
禁用 php-fpm 配置。并在 httpd.conf 文件中添加以下内容,这应该有效:
<FilesMatch "\.php$">
SetHandler "proxy:fcgi://localhost:9000"
</FilesMatch>
ProxyErrorOverride On
重新启动 Apache 和 PHP-FPM(PHP-FPM 可能不需要重新启动,但必须重新启动 Apache)。现在启用HTTP/2,它应该可以工作。
编辑
OP 在配置中的某些重定向中遇到了这个问题。
我修改了我的 Debian 9 安装 (Apache 2.4.25) 以允许 HTTP/2 支持。
我已经在线检查成功,页面 确实 服务,但问题在于在 .htaccess 中执行的重定向以映射示例站点。com/index.php/brands/mybrand 到一个不错的 url (site.com/brands/mybrand)。它根本不会发生。这是一个 Codeigniter 设置。
- 有问题的步骤似乎是当我禁用当前模块(
a2dismod php7.2
和mpm_prefork
)并启用 mpm 模块(a2enmod mpm_event
,但我也尝试过mpm_worker
) 支持 HTTP/2。 - 那时我得到 "file not found"(404 错误)
- 通过恢复这两个步骤,我恢复正常(当然没有 HTTP/2)
是否通过加载mpm_worker模块使下面的mod_rewrite.c条件无效?如果可以,我该如何更换它?
EDIT: a detailed Log show me this error: AH01071: Got error 'Primary script unknown\n', referer: https://sitename.com/brands/
我的 .htaccess(在 index.php 所在的 brands 目录中)与之前的配置配合良好:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css|css)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>
IndexOptions +Charset=UTF-8
我的/etc/apache2/sites-enabled/default-ssl.conf相关内容包括:
<VirtualHost _default_:443>
# even without enabling here h2c or h2 I get the error
Protocols http/1.1
<Directory "/var/www/html">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
# since apache 2.4
Require all granted
</Directory>
</VirtualHost>
注意:我之前 运行 启用所需的其他模块的其他命令如下。我不需要触及任何东西就可以恢复到工作(非 HTTP/2)配置:
apt-get install php7.2-fpm
a2enmod proxy_fcgi setenvif
a2enconf php7.2-fpm
编辑:
问题是由内部重定向引起的。现已修复。
您没有正确配置 PHP-FPM。通过说 a2disconf php7.2-fpm
禁用 php-fpm 配置。并在 httpd.conf 文件中添加以下内容,这应该有效:
<FilesMatch "\.php$">
SetHandler "proxy:fcgi://localhost:9000"
</FilesMatch>
ProxyErrorOverride On
重新启动 Apache 和 PHP-FPM(PHP-FPM 可能不需要重新启动,但必须重新启动 Apache)。现在启用HTTP/2,它应该可以工作。
编辑
OP 在配置中的某些重定向中遇到了这个问题。