虎泰克博客

htaccess将HTTP访问重定向至HTTPS


非常实用的一个.htaccess规则,使用只需将下面代码另存为.htaccess文件,传到网站根目录

非常实用的一个.htaccess规则,使用只需将下面代码另存为.htaccess文件,传到网站根目录下即可。当然前提是你已经开通了.htaccess支持。

虎ovn泰ejihg克bm_新br闻orpp网ilsg版权所有,请勿未授权转载!!!


虎hsz泰ame克jza新vgyfa闻ybz网kkc版权所有,请勿未授权转载!!!

将 http 访问强制重定向至 https,代码如下:

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


虎luq泰ppcbd克yax新gzhcj闻lolcu网y版权所有,请勿未授权转载!!!

将 https 访问强制重定向至 http,代码如下:

RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^.*$ http://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]


虎zylc泰i克mp新eyrj闻jhwsw网shqq版权所有,请勿未授权转载!!!

以上修改的.htaccess规则最后一行里直接包含了301永久性转移,如只需要302临时性转移,请将规则最后一行R=301中的=301删除即可。但302临时性转移对搜索引擎不友好。而添加301永久性转移后,就变成了永久性转移----传递原来的权重。

虎pzl泰amgcb克rtx新gytn闻rj网ggt版权所有,请勿未授权转载!!!




Statement: all articles / drawings reproduced on this website are for the purpose of transmitting more information and facilitating discussion, which does not mean that the website, the host and the organizer agree with their opinions or confirm the authenticity of their contents. The contents of the articles are for reference only. If the rights of the original author are violated, please contact the website administrator.

Sign in to comment

Comment list

    No data