<?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>猪,一个人的世界.&#187; 网站技术</title>
	<atom:link href="http://pigz.cn/blog/archives/category/web/feed" rel="self" type="application/rss+xml" />
	<link>http://pigz.cn/blog</link>
	<description>多看则清,多听则明,多思则准,多干则成.</description>
	<lastBuildDate>Wed, 18 Nov 2009 06:33:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>使用Apache的Rewrite解决JavaScript的跨域问题</title>
		<link>http://pigz.cn/blog/archives/33</link>
		<comments>http://pigz.cn/blog/archives/33#comments</comments>
		<pubDate>Tue, 07 Apr 2009 15:12:25 +0000</pubDate>
		<dc:creator>PigZ</dc:creator>
				<category><![CDATA[网站技术]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[跨域]]></category>

		<guid isPermaLink="false">http://pigz.cn/blog/?p=33</guid>
		<description><![CDATA[关于各大浏览器对js跨域的限制不再敷述.
网上也有各种各样的解决办法,但都不是很完美.
翻看了一些资料后,尝试了一下,觉得apache的rewrite对跨域问题的解决还算不错.
把相关的重点事项记录一下.
1.首先要开启apache的rewrite和proxy模块.
修改apache配置文件,去掉以下三行前边的#号
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so
重启apache.
PS:如果未开启proxy模块,会导致rewrite规则中的P参数无效;如果rewrite模块未开启-.-那就&#8230;没的说了.
2.编写rewrite规则
RewriteEngine On
RewriteBase /
RewriteRule ^jump.*  http://www.zzjuhe.net/ [L,R,P,NC] 
需要注意的是RewriteRule 后边的重写规则参数
L不解释了
R是强制外部重定向,因为是要跨域定向到外部域,所以必须有R
P是强制使用代理转发,这个也是必须的.
NC是不区分大小写,这个倒是可选,但是为了增加兼容性,最好还是加上.
这里特别要注意的是P参数,如果没有P参数,ie会弹出&#8221;该页正在访问其控制范围外的信息,这有些危险.是否继续?&#8221;的对话框.点&#8221;是&#8221;的话还是可以继续的;firefox会得到&#8221;302 Found&#8221;的错误提示.
做完以上工作后,就基本OK了,现在可以尝试用ajax请求http://pigz.cn/jump/,会发现得到的数据是apache已经重新定向了的http://www.zzjuhe.net/的数据.
]]></description>
		<wfw:commentRss>http://pigz.cn/blog/archives/33/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
