Nginx配置http跳转https访问
作者:admin 日期:2021-11-26
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
PHP UNICODE编码(\u) 和UTF-8 之间转换
作者:admin 日期:2021-11-22
PHP代码
- header("content:application/json;chartset=uft-8");
- //将内容进行UNICODE编码
- function unicode_encode($name){
- $name = iconv('UTF-8', 'UCS-2', $name);
- $len = strlen($name);
- $str = '';
- for ($i = 0; $i < $len - 1; $i = $i + 2)
- {
- $c = $name[$i];
- $c2 = $name[$i + 1];
- if (ord($c) > 0)
- { // 两个字节的文字
- $str .= '\u'.base_convert(ord($c), 10, 16).base_convert(ord($c2), 10, 16);
- }
- else
- {
- $str .= $c2;
- }
- }
- return $str;
- }
- //将UNICODE编码后的内容进行解码
- function unicode_decode($name){
- // 转换编码,将Unicode编码转换成可以浏览的utf-8编码
- $pattern = '/([\w]+)|(\\\u([\w]{4}))/i';
- preg_match_all($pattern, $name, $matches);
- if (!emptyempty($matches))
- {
- $name = '';
- for ($j = 0; $j < count($matches[0]); $j++)
- {
- $str = $matches[0][$j];
- if (strpos($str, '\\u') === 0)
- {
- $code = base_convert(substr($str, 2, 2), 16, 10);
- $code2 = base_convert(substr($str, 4), 16, 10);
- $c = chr($code).chr($code2);
- $c = iconv('UCS-2', 'UTF-8', $c);
- $name .= $c;
- }
- else
- {
- $name .= $str;
- }
- }
- }
- return $name;
- }
- $utf8_name = 'MY,你的东西'; //MY,\u4f60\u5927\u7237\u7684
- $unicode_name=unicode_encode($utf8_name);
- echo $unicode_name . ' -> '.unicode_decode($unicode_name);
- echo unicode_decode("\u0000");
Wordpress安装在windows下web.config伪静态规则
作者:admin 日期:2021-11-20
<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>
广告位