预览模式: 普通 | 列表

Nginx配置http跳转https访问

nginx的rewrite方法
可以把所有的HTTP请求通过rewrite重写到HTTPS上
 
server{
   listen 80;
   server_name XXXXX.com;  //你的域名
   rewrite ^(.*)$  https://XXXXXX.com permanent;
   location ~ / {
   index index.html index.php index.htm;
}
}
 
server{
   listen 80;
   server_name XXXXX.com;  //你的域名
   return 301 https://$server_name$request_uri;
   location ~ / {
   index index.html index.php index.htm;
}
}
 
server{
   listen 80;
   server_name XXXXX.com;  //你的域名
   rewrite ^(.*)$  https://$host$1 permanent;
   location ~ / {
   index index.html index.php index.htm;
}
}
 
nginx的497状态码
497 – normal request was sent to HTTPS  
当前站点只允许HTTPS访问,当使用HTTP访问nginx会报出497错误码
可以使用error_page 把497状态码链接重新定向到HTTPS域名上
 
server{
   listen 80;
   server_name XXXXX.com;  //你的域名
   error_page 497  https://$host$uri?$args;
   location ~ / {
   index index.html index.php index.htm;
}
}
 
meta刷新作用将http跳转到HTTPS
index.html
<html>
 <meta http-equiv=”refresh” content=”0;url=https://XXXX.com/”>
 </html>
 
nginx配置
 
 
   listen 80;
   server_name XXXXX.com;  //你的域名
   location ~ / {
   root /var/www/test/;
   index index.html index.php index.htm;
   }
   error_page 404 https://xxxx.com

 

Tags: nginx

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 66

PHP UNICODE编码(\u) 和UTF-8 之间转换

 

PHP代码
  1. header("content:application/json;chartset=uft-8");  
  2.    
  3.    
  4. //将内容进行UNICODE编码  
  5. function unicode_encode($name){  
  6.     $name = iconv('UTF-8''UCS-2'$name);  
  7.     $len = strlen($name);  
  8.     $str = '';  
  9.     for ($i = 0; $i < $len - 1; $i = $i + 2)  
  10.     {  
  11.         $c = $name[$i];  
  12.         $c2 = $name[$i + 1];  
  13.         if (ord($c) > 0)  
  14.         {    // 两个字节的文字  
  15.             $str .= '\u'.base_convert(ord($c), 10, 16).base_convert(ord($c2), 10, 16);  
  16.         }  
  17.         else  
  18.         {  
  19.             $str .= $c2;  
  20.         }  
  21.     }  
  22.     return $str;  
  23. }  
  24. //将UNICODE编码后的内容进行解码  
  25. function unicode_decode($name){  
  26.     // 转换编码,将Unicode编码转换成可以浏览的utf-8编码  
  27.     $pattern = '/([\w]+)|(\\\u([\w]{4}))/i';  
  28.     preg_match_all($pattern$name$matches);  
  29.     if (!emptyempty($matches))  
  30.     {  
  31.         $name = '';  
  32.         for ($j = 0; $j < count($matches[0]); $j++)  
  33.         {  
  34.             $str = $matches[0][$j];  
  35.             if (strpos($str'\\u') === 0)  
  36.             {  
  37.                 $code = base_convert(substr($str, 2, 2), 16, 10);  
  38.                 $code2 = base_convert(substr($str, 4), 16, 10);  
  39.                 $c = chr($code).chr($code2);  
  40.                 $c = iconv('UCS-2''UTF-8'$c);  
  41.                 $name .= $c;  
  42.             }  
  43.             else  
  44.             {  
  45.                 $name .= $str;  
  46.             }  
  47.         }  
  48.     }  
  49.     return $name;  
  50. }  
  51. $utf8_name = 'MY,你的东西';  //MY,\u4f60\u5927\u7237\u7684  
  52. $unicode_name=unicode_encode($utf8_name);  
  53. echo $unicode_name . ' -> '.unicode_decode($unicode_name);  
  54.    
  55. echo  unicode_decode("\u0000");  

 

Tags: php

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 60
<rewrite>
      <rules>
<rule name="WordPress: http://www.tyzqwl.com/blog" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule></rules>
    </rewrite>

Tags: wordpress

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 68

 广告位

↑返回顶部↑