HTACCESS 问题导致 401 和多个 302


HTACCESS Issues Resulting in 401 and Multiple 302

我有一个基于PHP MVC框架的网站。

我已经为整个网站添加了密码保护,直到我准备好向公众开放。

我正在尝试实现站点范围的HTTPS。我已经在服务器(Apache)上安装了EV SSL证书。

当我将代码添加到 htaccess 以强制所有 url 重定向到 https 时,我收到"由于多次 402 重定向而导致的 402 错误"。

我在访问我的网站时收到的确切错误是:此网页具有重定向循环。ERR_TOO_MANY_REDIRECTS

我已经对这个话题进行了大量研究,但没有解决方案。对我的错误的任何帮助和解释将不胜感激。

这是我的htaccess文件中的确切代码:

DirectoryIndex index.php
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css  text/javascript
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
# start https
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.org/$1 [R,L]
# end https
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
# header modifiers
# By default allow all access
Order allow,deny
Allow from all
# Password protect entire site until launch
AuthType Basic  
AuthName "restricted area"  
AuthUserFile /home/mydirectory/public_html/.htpasswd  
require valid-user
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

上面的代码总是对我有用。您可以直接在浏览器上访问安全(https)页面吗?

确保您已为 HTTPS 正确配置了 apache。

配置示例:

<VirtualHost *:443>
DocumentRoot /var/www/html
ServerName www.yourdomain.com
SSLEngine on
SSLCertificateFile /path/to/your_domain_name.crt
SSLCertificateKeyFile /path/to/your_private.key
SSLCertificateChainFile /path/to/DigiCertCA.crt
</VirtualHost>