虎泰克博客

htaccess将HTTP访问重定向至HTTPS


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

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

虎buogo泰hzdcu克mvwg新g_闻d_ak网b版权所有,请勿未授权转载!!!


虎s泰fq克aen新m_vxh闻uwn网vip版权所有,请勿未授权转载!!!

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

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


虎wc泰_cy克ma新pqttz闻ma网tpy版权所有,请勿未授权转载!!!

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

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


虎p泰k克m新skii闻mihoa网erg版权所有,请勿未授权转载!!!

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

虎i泰h克v新oy闻sgyqn网n版权所有,请勿未授权转载!!!




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