200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > LNMP Apache http跳转到https 不带www跳转到www域名

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

时间:2022-05-24 03:19:30

相关推荐

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

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

确认是否开启rewrite重写模块

配置文件一般位于/usr/local/apache/conf/httpd.conf

找到

#LoadModule rewrite_module modules/mod_rewrite.so, 去掉#号

站点配置文件设置

注意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

修改站点根目录.htaccess文件

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

RewriteEngine On

RewriteCond %{HTTP_HOST} ^ [NC]

RewriteRule ^(.*)$ /$1 [L,R=301]

RewriteCond %{SERVER_PORT} 80

RewriteRule ^(.*)$ /$1 [L,R=301]

记得重启Apache

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。