首页 > 编程技术 > html

Nginx下301重定向域名方法

发布时间:2016-9-20 19:00

进行了301重定向,把www.111cn.net和111cn.net合并,并把之前的域名也一并合并. 有两种实现方法,第一种方法是判断nginx核心变量host(老版本是http_host):
server {
server_name www.111cn.net 111cn.net ;
if ($host != 'www.111cn.net' ) {
rewrite ^/(.*)$ http://www.111cn.net/$1 permanent;
}
...
}
第二种方法:
server {
server_name 111cn.net;
rewrite ^/(.*) http://www.111cn.net/$1 permanent;
}

测试了第一种方法ok,这两种方法中, permanent是关键,详细说明见nginx重定向规则说明。

last – 基本上都用这个flag。
break – 中止rewirte,不在继续匹配
redirect – 返回临时重定向的http状态302
permanent – 返回永久重定向的http状态301

好了,现在可以检查结果,这里可以看返回的http头信息:

http://www.seo教程consultants.com/tools/headers.asp教程

第二种方法没有测试成功...


--------------------------------------------------------------------------------
测试是否定向成功

http://qinfy.net/301-redirect-for-nginx/

输入指令~

/usr/local/nginx/sbin/nginx -t
提示:
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful

测试成功~ 重启nginx~ 输入指令~

/usr/local/nginx/sbin/nginx -s reload
重启之后测试一下~是否成功设定完成! 输入指令~

curl -i imcat.tk


会输出:

http/1.1 301 moved permanently
server: nginx/0.7.65
date: tue, 03 aug 2010 01:12:37 gmt
content-type: text/html
content-length: 185
connection: keep-alive
location: http://111cn.net/

 

header('content-type:text/html;charset=utf-8;');
include_once('sinaeditor.class.php教程');
/*********************************************************************************/
//这里判断表单提交动作,然后赋值给$content;
if($_get['act']=='subok') die(htmlspecialchars($content=$_post['gently_editor']));
/*********************************************************************************/
$editor=new sinaeditor('gently_editor');
$editor->value='<img" width=100% src="../logo.gif"><h2>新浪博客编辑器php图片上传版!</h2>';
$editor->basepath='.';
$editor->height=500;
$editor->width=650;
$editor->autosave=false;
?>
<div align="center">
<form name="form1" id="form1" method="post" action="index.php?act=subok">
<?php
 $editor->create();
?><br />
<input type="submit" value="提交">
<input type="reset" value="重置">
</form>
</div>

<?
class sinaeditor{
 var $basepath;
 var $width;
 var $height;
 var $ename;
 var $value;
 var $autosave;
 function sinaeditor($ename){
  $this->ename=$ename;
  $this->basepath='.';
  $this->autosave=false;
  $this->height=460;
  $this->width=630;
 }
 function __construct($ename){
  $this->sinaeditor($ename);
 }
 function create(){
  $readcookie=$this->autosave?1:0;
  print <<<eot
  <textarea name="{$this->ename}" id="{$this->ename}" style="display:none;">{$this->value}</textarea>
  <iframe" width=100% src="{$this->basepath}/edit/editor.htm?id={$this->ename}&readcookie={$readcookie}" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" width="{$this->width}" height="{$this->height}"></iframe>
eot;
 }
}
?>

编辑器下载地址
http://down.111cn.net/webedit/2010/0819/20307.html

本文章提供一款jquery javascript获取图片的宽高代码哦,第一款是基于jquery的例子,第二款是利用js获取上传图片的高度与宽度代码。

jquery例子

var img = $(‘#imageid');

var theimage = new image();t

heimage.src = img.attr(“src”);

alert(“width: ” + theimage.width);

alert(“height: ” + theimage.height);


js例子

var img = new image();
img.onload = function(){
 宽度=this.width
 高度=this.height
}
img.src = 图片地址;

现在浏览器多啊,如有 chrome/ff/ie,那我们设计师就会碰到很多问题,如果不兼容问题,今天我们要讲的是关于iframe的 frameborder在不同浏览器不兼容解决方法。

代码如下:

var iframe = document.createelement("iframe");
iframe.id = "frame-" + index;
iframe.src = url;
iframe.width = "100%";
iframe.marginwidth = "0";
iframe.scrolling = "no";
iframe.frameborder="0";

使用ie中“查看选定区域源代码”发现创建的iframe代码是<iframe frameborder=0/>,网上搜了下资料,原来是ie不认小写,我晕死....

使用
 代码如下:

setattribute("frameborder", "0", 0);


//问题解决了。


 代码如下:

var iframe = document.createelement("iframe");
iframe.id = "frame-" + index;
iframe.src = url;
iframe.width = "100%";
iframe.marginwidth = "0";
iframe.scrolling = "no";
iframe.setattribute("frameborder", "0", 0); //最后一个0表示是否区别大小写,问题解决
关于中文的正则表达式, 应该是^[\\u4E00-\\u9FFF]+$, 和论坛里常被人提起的^[\\u4E00-\\u9FA5]+$很接近需要注意的是论坛里说的^[\\u4E00-\\u9FA5]+$这是专门用于匹配简体中文的正则表达式, 实际上繁体字也在里面, 我用测试器测试了下, 也通过了, 当然, ^[\\u4E00-\\u9FFF]+$也是一样的结果

关于中文的正则表达式, 应该是^[u4e00-u9fff]+$, 和论坛里常被人提起的^[u4e00-u9fa5]+$很接近需要注意的是论坛里说的^[u4e00-u9fa5]+$这是专门用于匹配简体中文的正则表达式, 实际上繁体字也在里面, 我用测试器测试了下, 也通过了, 当然, ^[u4e00-u9fff]+$也是一样的结果


正则表达式匹配汉字中文var

 str = "网页制作教程ww.111cn.net";
if (/^[u4e00-u9fa5]+$/.test(str)) {
alert("该字符串全部是中文");
} else {
alert("该字符串不全部是中文");
}


php教程正则中文

<?php
$str = "php编程";
if (preg_match("/^[u4e00-u9fa5]+$/",$str)) {
print("该字符串全部是中文");
} else {
print("该字符串不全部是中文");
}
?>


匹配中文字符的正则表达式: [u4e00-u9fa5]
匹配双字节字符(包括汉字在内):[^x00-xff]
匹配空行的正则表达式:n[s ¦ ]*r
匹配html标记的正则表达式:/ <(.*)> .* </1> ¦ <(.*) /> /
匹配首尾空格的正则表达式:(^s*) ¦(s*$)

标签:[!--infotagslink--]

您可能感兴趣的文章: