子域和文件夹
刚刚启动了一个网站,我在主域上有一个 /img
目录。我想设置一个能够使用 /img
文件夹的子域(其中文件夹只是主目录中的另一个文件夹),但它不起作用。
/img 和 /subdomain 文件夹位于同一级别,因此要显示主域中的图像,我键入: 对于 /subdomain 我输入:
我收到该网站的 404 错误: http://subdomain.example.com /img/image.jpg 如您所见,我希望它链接到 http://www.example .com/img/image.jpg
谁能告诉我如何实现这一目标?我不想将图像链接到他们的互联网目录(即http://www...),因为我想修改我计算机上的网站并通过 ftp 上传它们。
我确信这只是我搞砸了或者不完全理解的事情。提前致谢!
Just started a site and I have an /img
directory on the main domain. I would like to set up a subdomain(where the file folder is just another one in the main directory) that is able to use the /img
folder but it doesn't work.
The /img and /subdomain folders are on the same level, so to display images in the main domain I type: <img src="img/image.jpg">
and for the /subdomain I type: <img src="../img/image.jpg">
and I get a 404 error for the site: http://subdomain.example.com/img/image.jpg
As you can see, I want it to be linking to http://www.example.com/img/image.jpg
Can anyone tell me how to achieve this? I would prefer not to link images to their internet directory (i.e. http://www...) because I would like to modify the sites on my computer and upload them via ftp.
I'm sure it's just something that I am messing up or don't completely understand. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
相对路径始终相对于 URI。如果您的 http://subdomain.example.com/ 页面包含指向 ../ 的链接img/image.jpg,Web 服务器将其转换为 http:// 的链接subdomain.example.com/../img/image.jpg。显然,Web 服务器无法提供其根目录之上的任何内容(这就是拥有根目录的全部意义)。
您的网络服务器配置为仅提供 /subdomain 目录中的内容,但显然 /img 不在该目录内,因此无法提供服务。您需要做的是将您的网络服务器配置为在收到对 http://subdomain.example.com/img/
对于 Apache,这可以通过 mod_alias。
摘要:使用 mod_alias 将请求映射到 http://subdomain.example.com/img/ 到目录/img。
Relative paths are always relative to a URI. If you have a page at http://subdomain.example.com/ containing a link to ../img/image.jpg, the web server translates it into a link to http://subdomain.example.com/../img/image.jpg. Obviously the web server can't serve anything above it's root directory (that's the whole point of having a root).
Your webserver is configured to only serve content in the /subdomain directory, but obviously /img is not inside that directory, and can't thus be served. What you need to do is configure your webserver to look in /img (the directory on your filesystem) instead of /subdomain/img when it gets an request for any content at http://subdomain.example.com/img/
With Apache this can be done with mod_alias.
Summary: Use mod_alias to map requests to http://subdomain.example.com/img/ to the directory /img.