當你的站點使用了HTTPS之后,你可能會想把所有的HTTP請求(即端口80的請求),全部都重定向至HTTPS(即端口443)。這時候你可以用以下的方式來做到:(Apache mod_rewrite)
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://Vevb.com/$1 [R=301,L]</IfModule>
把這段代碼放在.htaccess文件,即可實現HTTP到HTTPS的重定向。
而當你又想用回HTTP的時候,反過來就可以了:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{SERVER_PORT} 443 RewriteRule ^(.*)$ http://Vevb.com/$1 [R=301,L]</IfModule>
其中R=301表示Moved Permanently,即告訴搜索引擎或者瀏覽器下去直接訪問后者的地址,如果只是試驗性地重定向,可以使用R=302(Found)。
新聞熱點
疑難解答