每件事都运行良好,包括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>
3 回答
将DirectoryIndex和Redirect永久添加到虚拟主机:80
检查清单
命令启用
sudo a2enmod重写
sudo service apache2 restart
RewriteRule . ^ index.php [L]
查看此主题以获取更多信息Thread
你能改变
RewriteRule .? %{ENV:BASE}/index.php [L]
到RewriteRule ^ index.php [L]
编辑:
你能看看这个重写规则 . 如果有效,请稍后添加您的https和身份验证条件 .