<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>杨思为 &#124; 我们一家 &#187; 网站前端性能</title>
	<atom:link href="http://yangsiwei.com/tag/%e7%bd%91%e7%ab%99%e5%89%8d%e7%ab%af%e6%80%a7%e8%83%bd/feed" rel="self" type="application/rss+xml" />
	<link>http://yangsiwei.com</link>
	<description>杨思为 &#124; 宝宝博客 &#124; 宝宝照片 &#124; 育儿经验</description>
	<lastBuildDate>Sun, 15 Jan 2012 15:02:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>WordPress附件二级域名设置</title>
		<link>http://yangsiwei.com/setting-another-domain-for-media-in-wordpress</link>
		<comments>http://yangsiwei.com/setting-another-domain-for-media-in-wordpress#comments</comments>
		<pubDate>Sun, 27 Dec 2009 14:07:05 +0000</pubDate>
		<dc:creator>思为爸爸</dc:creator>
				<category><![CDATA[WordPress插件]]></category>
		<category><![CDATA[wordpress插件]]></category>
		<category><![CDATA[网站前端性能]]></category>

		<guid isPermaLink="false">http://yangsiwei.com/?p=2186</guid>
		<description><![CDATA[在《高性能网站建设指南》中，雅虎的前端工程师Steve Souders明确指出为网站的静态组件增加一个单独的域名能够增加网页组件的并行下载速度，从而提高网页的响应速度。因此，本插件的主要目的就是为杨思为网站中的图片、附件（所有保存在wp-content）目录下的多媒体设置一个二级域名。 WordPress附件二级域名设置插件实现原理： 1、通过“the_content”filter hook将要显示的所有包含“一级域名+wp-content”的内容替换为所要设置的二级域名。 2、在apache或者ngnix中通过mod_rewrite进行地址重写 插件实现代码： &#60;?php /* Plugin Name: 设置多媒体二级域名 Version: 1.0 Plugin URI: http://yangsiwei.com/setting-another-domain-for-media-in-wordpress Description: 为wp-content下的多媒体设置二级域名，增加并行请求数提高网页响应速度。 Author: 思为爸爸 Author URI: http://yangsiwei.com/ TODO: 1、增加配置页面 2、自动生成apache和ngnix下的地址重写正则表达式，并直接写入.htaccess文件中。 */ /** * Enter description here&#8230; * * @todo 新的域名可以通过配置页面进行配置 * * @param unknown_type $content * @return unknown */ function setting_another_domain_for_media($content) { $content = str_replace( get_bloginfo(&#8216;home&#8217;) . &#8216;/wp-content/&#8217;, [...]]]></description>
			<content:encoded><![CDATA[<p>在《高性能网站建设指南》中，雅虎的前端工程师Steve Souders明确指出为网站的静态组件增加一个单独的域名能够增加网页组件的并行下载速度，从而提高网页的响应速度。因此，本插件的主要目的就是为杨思为网站中的图片、附件（所有保存在wp-content）目录下的多媒体设置一个二级域名。</p>
<h2>WordPress附件二级域名设置插件实现原理：</h2>
<blockquote><p>1、通过“the_content”filter hook将要显示的所有包含“一级域名+wp-content”的内容替换为所要设置的二级域名。</p>
<p>2、在apache或者ngnix中通过mod_rewrite进行地址重写</p></blockquote>
<h2>插件实现代码：</h2>
<blockquote><p>&lt;?php<br />
/*<br />
Plugin Name: 设置多媒体二级域名<br />
Version: 1.0<br />
Plugin URI: http://yangsiwei.com/setting-another-domain-for-media-in-wordpress<br />
Description: 为wp-content下的多媒体设置二级域名，增加并行请求数提高网页响应速度。<br />
Author: 思为爸爸<br />
Author URI: http://yangsiwei.com/</p>
<p>TODO:<br />
1、增加配置页面<br />
2、自动生成apache和ngnix下的地址重写正则表达式，并直接写入.htaccess文件中。<br />
*/</p>
<p>/**<br />
* Enter description here&#8230;<br />
*<br />
* @todo 新的域名可以通过配置页面进行配置<br />
*<br />
* @param unknown_type $content<br />
* @return unknown<br />
*/<br />
function setting_another_domain_for_media($content) {<br />
$content = str_replace( get_bloginfo(&#8216;home&#8217;) . &#8216;/wp-content/&#8217;, &#8216;http://pic.yangsiwei.com/&#8217;, $content);<br />
return $content;<br />
}</p>
<p>add_filter( &#8216;the_content&#8217;, &#8216;setting_another_domain_for_media&#8217;, 12 )</p>
<p>?&gt;</p></blockquote>
<p>完成以后插件开发后，在ngnix中对地址进行重写，重写规则如下：</p>
<blockquote><p>server<br />
{<br />
listen 80;<br />
server_name pic.yangsiwei.com;<br />
index index.html index.php index.htm;<br />
root /www/yangsiwei.com/wp-content/;<br />
}</p></blockquote>
<p>保存，重启ngnix，内容中上传的多媒体以及保存在wp-content中的任何组件都将通过新的二级域名进行访问，一切OK。</p>
]]></content:encoded>
			<wfw:commentRss>http://yangsiwei.com/setting-another-domain-for-media-in-wordpress/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

