一切正常,包括浏览器上的HTTP到https重定向
http://example.com/app/login 404
https://example.com/app/login 404
http://www.example.com/app/login 404
https://www.example.com/app/login 404
http://example.com/index.php/app/login OK
https://example.com/app/index.php/login OK
http://www.example.com/index.php/app/login OK
https://www.example.com/index.php/app/login OK
由邮递员测试的网址
http到https重定向可以很好地尊重www或非www
服务器 Ubuntu 18.04 Apache 2.4.29
/etc/hosts
206.189.85.* example.com #server ip address
206.189.85.* www.example.com
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
/etc/apache2/sites-available/example.com.conf
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/example.com/public
<Directory /var/www/example.com/public/>
Options -Indexes +FollowSymLinks +MultiVies
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
LogLevel warn
</VirtualHost>
/etc/apache2/sites-available/example.com-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin admin@example.com
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/example.com/public
SSLEngine On
<Directory /var/www/html/example.com/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
</VirtualHost>
</IfModule>
.htaccess内容
DirectoryIndex index.php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
答案 0 :(得分:0)
将DirectoryIndex添加并永久重定向到您的虚拟主机:80
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName www.example.com
ServerAlias example.com
DirectoryIndex index.php
DocumentRoot /var/www/example.com/public
Redirect permanent / https://www.example.com/
<Directory /var/www/example.com/public/>
Options -Indexes +FollowSymLinks +MultiVies
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
LogLevel warn
</VirtualHost>
答案 1 :(得分:0)
检查列表
您的apache a2enmod重写是否已启用?
启用
的命令sudo a2enmod重写
sudo服务apache2重新启动
将此行添加到.htaccess结尾
RewriteRule。 ^ index.php [L]
检查此线程以获取更多信息 Thread
答案 2 :(得分:0)
你能改变吗
RewriteRule .? %{ENV:BASE}/index.php [L]
至
RewriteRule ^ index.php [L]
编辑:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
您可以检查此重写规则吗?如果可以,请稍后添加https和身份验证条件。