使用 .htaccess 在 2 个域中共享文件夹
我有 2 个子域
c:\wamp\www\websiteA\ - http://websiteA/
c:\wamp\ www\websiteB\ - http://websiteB/
在 websiteA 内有一个用于存储图片的文件夹
c:\wamp\www\websiteA \photos\
为了 websiteB 想要访问 websiteA photo 在 websiteB 的 html 中,我必须像
<img src="http://websiteA/photos/1.jpg" />
问题是我不想在 websiteB 中公开 websiteA 域,因为两个域位于一台机器内。是否可以实现虚拟主机之类的功能?
我也不想公开 websiteA 的物理路径,也不想重复数据。
我想在 websiteB .htaccess 中做点什么?
我的目标是在 websiteB html 中能够使用自己的域显示照片,
<img src="http://websiteB/photos/1.jpg" />
编辑:我认为问题是这样问的 方式更好,以便用户请求 http://websiteB/photo/1.jpg, 后端实际上从以下位置请求文件 http://websiteA/photo/1.jpg,.htaccess 有什么想法吗?
我是 htaccess 的新手,我尝试过 .htaccess,但没有成功
RewriteEngine On
RewriteRule http://websiteA/photos/1.jpg http://websiteB/photos/1.jpg[NC,L]
非常感谢!
PS:解决方案需要在windows/linux环境下工作。
I got 2 sub-domains
c:\wamp\www\websiteA\ - http://websiteA/
c:\wamp\www\websiteB\ - http://websiteB/
inside websiteA got a folder for storing picture
c:\wamp\www\websiteA\photos\
in order websiteB want to access websiteA photo in websiteB's html I have to do link like
<img src="http://websiteA/photos/1.jpg" />
the problem is I don't want to expose websiteA domain in websiteB, since two domain is inside one machine. Is it possible to achieve something like virtual host?
I also don't want to expose the physical path for websiteA, and don't want to duplicate the data.
I am thinking do something in websiteB .htaccess?
My goal is in websiteB html able to display photo with it own domain,
<img src="http://websiteB/photos/1.jpg" />
Edit: I think the question ask it this
way is better in order user request
http://websiteB/photo/1.jpg, the
backend actually request the file from
http://websiteA/photo/1.jpg, any idea do from .htaccess?
I am new in htaccess, I tried in .htaccess, but not success
RewriteEngine On
RewriteRule http://websiteA/photos/1.jpg http://websiteB/photos/1.jpg[NC,L]
Many Thanks!!!
PS: Solution need to work either windows / linux environment.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Windows 上,这取决于您使用的文件系统。
NTFS:http://en.wikipedia.org/wiki/NTFS_symbolic_link
FAT32 不支持符号链接。
On Windows it depends on what filesystem you're using.
NTFS: http://en.wikipedia.org/wiki/NTFS_symbolic_link
FAT32 doesn't support symlinks.
听起来像狗吗?能给出理由吗?
您可能正在寻找的是代理。在谷歌上查一下
Sound doggy? Can you supply reason?
What you are probably looking for is a proxy. Check it out on google
我想我得到了我的解决方案,不确定是否完美
在 websiteB 的 .htaccess 中,
我发现它不太完美的是当我输入时
http://websiteB/photos/1.jpg,它将重定向到 http://websiteA/photos/1.jpg
但在 HTML 中,我输入
It 能够加载 http://websiteA/photos/1.jpg 不更改 URL。这对我来说看起来不错。
I think I got my solution, not sure is perfect or not
inside .htaccess for websiteB
the thing I found it not so perfect is when I enter
http://websiteB/photos/1.jpg, it will redirect to http://websiteA/photos/1.jpg
but inside the HTML, I type
It able to load http://websiteA/photos/1.jpg without change the URL. That's look OK for me.