<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://jb51.net/$1 [R=301,L]
</If编程客栈Module>
把这段代码编程客栈放在.htaccess文件,即可实现HTTP到HTTPS的重定向。
而当你又想用回HTTP的时候,反过来就可以了:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{SERVER_PORT} 443 RewriteRule ^(.*)$ http://jb51.net/$编程客栈1 [R=301,L] </IfModule>
其中R=301表示Moved Permane编程客栈ntly,即告诉搜索引擎或者浏览器下去直接访问后者的地址,如果只是试验性地重定向,可以使用R=302(Found)。
本文标题: Apache mod_rewrite实现HTTP和HTTPS重定向跳转
本文地址: http://www.cppcns.com/os/linux/126183.html
© 著作权归作者所有
举报
发表评论
0/200