我正在开发一个在子域上运行的web应用程序。在代码中我使用了相对URL的所有地方。没什么特别的,只是正常的方式。
我刚刚上传了该网站,但我找不到任何要包含的文件。例如,这现在正在运作:
Site URL: sub.domain.com
CSS files are in: sub.domain.com/css/
Adding the following to the index.php **is working:**
<link rel="stylesheet" href="/css/styleSomething.css">
但是包含PHP文件却无法正常工作
Site URL: sub.domain.com
PHP Include files are in: sub.domain.com/inc/
Adding the following to the index.php is **not** working:
require_one(/inc/config.php)
如果我将URL更改为以./开头或根本没有斜杠,则会找到主页的文件。但是当访问者导航到不同的页面时,这不会起作用。
我在这里错过了一些这是托管的问题吗?
答案 0 :(得分:1)
您可以使用<base>
标记设置网站的根网址:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
以下内容适用于您的示例:
<base href="http://www.blah.com/yadda1/yadda2">
<link rel="stylesheet" href="css/styleSomething.css">
这将引用http://www.blah.com/yadda1/yadda2/css/styleSomething.css
的样式表。
如果您使用的是PHP并使用多个URL,请将基本URL放在变量中:
<base href="<?php echo $base_url; ?>">
答案 1 :(得分:0)
如果我理解正确,您将在/ rel1下的页面位于服务器的根目录下。 如果是这样,请尝试使用/rel1/css/style.css。