虎泰克博客

htaccess将HTTP访问重定向至HTTPS


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

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

虎t泰qhhbs克xqo新bet闻t网ngwh版权所有,请勿未授权转载!!!


虎wfs泰p克goimt新yga闻soh网_dke版权所有,请勿未授权转载!!!

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

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


虎xm泰hptt克fnpof新zp闻uvh网oz版权所有,请勿未授权转载!!!

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

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


虎x泰_克pqdj新ncyya闻v网xp版权所有,请勿未授权转载!!!

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

虎nee泰jys克ajiy新wwit闻z网ntp版权所有,请勿未授权转载!!!




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