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

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

  1. 确认是否开启rewrite重写模块
    配置文件一般位于/usr/local/apache/conf/httpd.conf
    找到
    #LoadModule rewrite_module modules/mod_rewrite.so, 去掉#号

  2. 站点配置文件设置
    注意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

相关文章:

  • 2022-12-23
  • 2021-12-08
  • 2021-07-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-12
  • 2021-07-18
相关资源
相似解决方案