apache实现http自动转为https

1.确认此服务器apache已经配置过证书可以用https访问到

2.确认/etc/apache2/ports.conf 下有

Listen 80
Listen 443

3.配置虚礼主机定将域名位到指定文件夹

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/laravel/public
    ServerName www.uipxw.com

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/laravel/public
    ServerName www.uipxw.com

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

两条记录相同监听端口不同

4.无框架在需要转为https的入口新建。.htaccess文件

写入

RewriteEngine On 

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

5.有框架在需要转为https的入口新建。.htaccess文件

RewriteEngine On

RewriteBase /

RewriteCond %{HTTPS} !=on

RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

BEGIN WordPress

RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L] 

如果不强制转为https框架的(.htaccess文件的内容应该是)

Options +FollowSymlinks -Multiviews
RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]

留下评论