Apache强制跳转转到HTTPS

莫南 | |被浏览47次| -1
|2018-05-28 22:45:05

Apache 转到 HTTPS

满意回答

2018-05-28 22:45:06

网站根目录新建 .htaccess


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


301跳转


<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R=301,L]
</IfModule>


站点绑定多个域名,只允许www.xorg.cn 跳转


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

###把网址更改为自己的###


高级用法 (可选)


RewriteEngine on
# 强制HTTPS
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{SERVER_PORT} 80
# 某些页面强制
RewriteCond %{REQUEST_URI} ^something_secure [OR]
RewriteCond %{REQUEST_URI} ^something_else_secure
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
# 强制HTTP
RewriteCond %{HTTPS} =on [OR]
RewriteCond %{SERVER_PORT} 443
# 某些页面强制
RewriteCond %{REQUEST_URI} ^something_public [OR]
RewriteCond %{REQUEST_URI} ^something_else_public
RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

一生二

 |采纳率:64%

您需要登录后才可以回复

全部回答(1)

  • 2018-05-28 22:45:06

    网站根目录新建 .htaccess


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


    301跳转



    RewriteEngine on
    RewriteBase /
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule (.*) https://%{SERVER_NAME}/$1 [R=301,L]



    站点绑定多个域名,只允许www.xorg.cn 跳转


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

    ###把网址更改为自己的###


    高级用法 (可选)


    RewriteEngine on
    # 强制HTTPS
    RewriteCond %{HTTPS} !=on [OR]
    RewriteCond %{SERVER_PORT} 80
    # 某些页面强制
    RewriteCond %{REQUEST_URI} ^something_secure [OR]
    RewriteCond %{REQUEST_URI} ^something_else_secure
    RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
    # 强制HTTP
    RewriteCond %{HTTPS} =on [OR]
    RewriteCond %{SERVER_PORT} 443
    # 某些页面强制
    RewriteCond %{REQUEST_URI} ^something_public [OR]
    RewriteCond %{REQUEST_URI} ^something_else_public
    RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

一个提问,一份期待;一条回答,一份回应。知识问与答,连接你和我!!

-- 来自问答管理员 admin

返回顶部