相对路径不适用于子域 [英] Relative paths don't work on subdomains

查看:79
本文介绍了相对路径不适用于子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个网站(假设为mysite.com).
当我在目录(mysite.com/part1/)中使用相对路径时,它们可以正常工作.但是,当我在子域(part1.mysite.com)上使用它们时,请指向part1.mysite.com

我的意思是,当我使用"../images/"时,它们不指向"mysite.com/images",而是指向"part1.mysite.com/images". AND"part1.mysite.com"仅是"mysite.com/part1/"的url子域.

请不要告诉我我不应该使用相对路径,因为必须这样做,因为我正在使用PHP glob()函数.

感激!
谢谢!

Hello,

I''ve a website (suppose mysite.com).
When I use relative paths in the directory (mysite.com/part1/) they work perfect. But when I use them on subdomain (part1.mysite.com), then point to part1.mysite.com

I mean when I use "../images/", they don''t point to "mysite.com/images", they point to "part1.mysite.com/images". AND "part1.mysite.com" is only the url subdomain for "mysite.com/part1/"

Please don''t tell me I shouldn''t use relative paths, because I have to, for that I''m using PHP glob() function.

Appreciated!
Thanks!

推荐答案

如果您在问这个问题,请不要告诉我们我们告诉您什么,什么不告诉我们.没有什么可以帮助您的,因为您没有遵循非常简单的逻辑.

当然,您应该使用相对路径,但是在不同的子域的情况下,相对路径仅等效于完整路径,因为层次结构的顶层已经不同.

由于您显然不了解子域,因此让我举一个Windows路径示例.如果您的工作目录是"d:/applications/myApplication/",那么"c:/applications"的相对路径是什么?当然是"c:/应用程序".子域的级别低于主域"mysite"的级别,但高于路径名中的所有内容.

根据 URI方案,在URI的路径"部分的顶部,在它的左侧有一个授权"部分,并且该授权部分总共(包括主机名"部分)包含域名的所有部分以及各个子域的所有级别)在层次结构中始终比路径部分更高.请参阅:
http://en.wikipedia.org/wiki/URI_scheme#Examples [ http://en.wikipedia.org/wiki/URL_redirection [ http://en.wikipedia.org/wiki/URL_redirection#Using_server-side_scripting_for_redirection [^ ]),
http://en.wikipedia.org/wiki/URL_rewriting [ http://www.addedbytes.com/for-beginners/url-rewriting-for-beginners / [ ^ ].

使用PHP,您可以使用http_redirect.请参阅:
http://www.devshed.com/c/a/PHP /How-to-Redirect-URLs-in-PHP/ [ http://php.net/manual/en/function.http-redirect.php [ ^ ],
http://php.net/manual/en/function.header.php [ ^ ].

有关使用PHP重写URL的信息,请参见:
http://www.cyberdesignz.com /blog/website-design/url-rewriting-top-5-ways-of-php-url-rewriting/ [
If you are asking the question, please don''t tell us what we tell you and what not. Nothing can help you because you fail to follow very simple logic.

Of course you should use relative path, but in case of a different sub-domain, the relative path is simply equivalent to the full paths, because the top level of the hierarchy is already different.

As you apparently don''t understand sub-domains, let me give you an example of Window paths. If your working directory is "d:/applications/myApplication/", what would be the relative path to "c:/applications"? Of course, "c:/applications". The level of the sub-domain in lower then the level of the main domain "mysite" but higher then anything in the path name.

In terms of URI scheme, on top of the "path" portion of the URI, there is an "authority" part on the left of it, and this authority part altogether (which includes "hostname" part which contains all part of domain names with all level of sub-domains) is always higher in hierarchy than the path part. Please see:
http://en.wikipedia.org/wiki/URI_scheme#Examples[^].



You may want to consider URL rewriting or URL redirection. Please see:
http://en.wikipedia.org/wiki/URL_redirection[^],
(pay attention for: http://en.wikipedia.org/wiki/URL_redirection#Using_server-side_scripting_for_redirection[^]),
http://en.wikipedia.org/wiki/URL_rewriting[^],
http://www.addedbytes.com/for-beginners/url-rewriting-for-beginners/[^].

With PHP, you can use http_redirect. Please see:
http://www.devshed.com/c/a/PHP/How-to-Redirect-URLs-in-PHP/[^],
http://php.net/manual/en/function.http-redirect.php[^],
http://php.net/manual/en/function.header.php[^].

On URL re-writing with PHP, please see:
http://www.cyberdesignz.com/blog/website-design/url-rewriting-top-5-ways-of-php-url-rewriting/[^].

—SA


这篇关于相对路径不适用于子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆