MENU

Apache http跳转到https, 不带www跳转到www域名

2019 年 01 月 04 日 • 阅读: 1777 • 运行环境

nginx

之前文章写过Nginx下如何设置跳转到https和www域名, 本篇说一下Apache下如何设置.

  1. 确认是否开启rewrite重写模块

配置文件一般位于

/usr/local/apache/conf/httpd.conf

找到

#LoadModule rewrite_module modules/mod_rewrite.so

去掉#号

  1. 站点配置文件设置
    注意Apache2.2和2.4版本写法不一样:

Apache 2.2

AllowOverride All 
Order allow,deny 
Allow from all 

Apache 2.4

AllowOverride All 
Order allow,deny 
Require all granted
  1. 修改站点根目录.htaccess文件

    http 301重定向到https, 并且不带www跳转到带www的域名


RewriteEngine On 
RewriteCond %{HTTP_HOST} ^wmsoho.com [NC] 
RewriteRule ^(.*)$ https://www.wmsoho.com/$1 [L,R=301] 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.wmsoho.com/$1 [L,R=301]

最后记得重启Apache