apache利用.htaccess进行反向域名绑定

[size=x-large]一、需求:[/size]
因公司带宽问题,所以想把静态资源移置CDN上(阿里或腾讯),但是某些前台js不支持跨域操作(createjs),但是页面文件为jsp页面,未移置到CDN上,createjs在对页面中的跨域图片就无权修改,所以想都在同一域名进入,页面文件正常访问apache下的,指定静态文件定位到CDN地址上。

[size=x-large]二、解决方案[/size]
1. 没有用到createjs的配置URL为CDN上的资源。

2. 用到createjs的配置URL为域名映射的apache下对应的URL。

[size=x-large]三、apache的配置[/size]
这里只是指定apache下某目录资源被访问跳转到CDN上请求,不是所以请求。如果是所以,可以直接配置在httpd.conf中。

[size=medium]1. 配置.htaccess,文件放在被访问的目录下[/size]

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase / # 在.htacess文件中被支持,如果是服务器配置文件,此规则会被忽略
RewriteRule ^(.*)$ http://frp.xxxxx.com/xxx/games/jianren2/$1 [P]
# RewriteRule ^(.*)$ http://frp.xxxxx.com/$1 [P] # P(force proxy) 强制使用代理转发。
</IfModule>

<Files .htaccess>
order allow,deny
deny from all
</Files>

[quote][url]http://www.jb51.net/article/25476.htm[/url]
[url]http://www.freehao123.com/park-domains/[/url][/quote]

[size=medium]2. 配置httpd.conf[/size]

# LoadModule rewrite_module modules/mod_rewrite.so 去除前面的 #

# 配置需要跳转的静态文件目录
<Directory "D:/Develop/Apache2.2/test/udp/games/jianren2">
Options FollowSymLinks
AllowOverride All # 如为None则不跳转
</Directory>

[quote][url]http://www.jb51.net/article/47889.htm[/url][/quote]

[size=medium]3. windows下创建.htaccess文件方法[/size]
1) 打开Windows内建的记事本;
2) 选取另存新文件“文件->另存为”;
3) 在另存为的“保存类型”下拉选单中选取“所有文件”类型,可以选择utf-8,也可以是ansi
4) 这时就可在“文件名”中输入.htaccess;
5) 选取要另存的路径再按下保存,一个.htaccess 文件就新增完成。
[quote][url]http://blog.sina.com.cn/s/blog_558839ae0100ev90.html[/url][/quote]


如:目录结构
DocumentRoot "D:/Develop/Apache2.2/test"
D:\Develop\Apache2.2\test\test 不需要跳转的目录
D:\Develop\Apache2.2\test\test\index.html apache下的此文件可以正常访问
D:\Develop\Apache2.2\test\udp\games\jianren2 为需要跳转到CND的目录
D:\Develop\Apache2.2\test\udp\games\jianren2\index.html apache下的此文件不能被访问,而是直接跳转到CDN,因为AllowOverride All,同时目录下有.htaccess文件指定了跳转规则。

效果:
[img]http://dl2.iteye.com/upload/attachment/0114/3097/2c01a6a2-b0f4-395a-a1a9-ec61a853c42a.jpg[/img]

[img]http://dl2.iteye.com/upload/attachment/0114/3099/74f86f3c-cf9b-301a-9657-f4a90bcf227e.jpg[/img]

已成功跳转的页面:
[img]http://dl2.iteye.com/upload/attachment/0114/3103/3a9d3f6e-4f7c-3b9c-b634-2ee0aa819326.jpg[/img]

apache下正常访问的页面:
[img]http://dl2.iteye.com/upload/attachment/0114/3101/ee462f17-7655-3dac-8e80-c32343b76377.jpg[/img]

apache下没有配置.htaccess时被访问到的页面
[img]http://dl2.iteye.com/upload/attachment/0114/3134/3e956627-f17e-3c04-8bff-75d8479e09cf.jpg[/img]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值