网站css和javascript无法在各自的文件夹中访问

时间:2016-02-22 00:17:50

标签: html css apache .htaccess

我的学校为每位学生提供免费网站空间。我创建了一个具有以下结构的网站

 - index.html
 - main-site/
  - css/
     - bootstrap.css
     - style.css
  - img/
  - js/
 - help-docs/
 - template/

当我在家用机器上访问该网站时,一切正常,并且css应用于页面。

然后我将文件夹上传到学校网站的根目录。我用我的默认index.html替换,并将文件夹放在与以前相同的结构中。但问题是,当我从新端点打开页面时,不会应用css。没有任何图片被加载,网站看起来只是裸露。

我已尝试更改文件夹和文件的权限以使其可访问,但这似乎不起作用。我甚至将所有内容都更改为777并且它没有任何区别。 我让我的一个朋友在他的页面上尝试我的网站,一切似乎都适合他。所以在这一点上我不确定问题是什么。

我还应该补充说,网络服务器是apache

到目前为止,在我的.htaccess文件中,我有以下内容:

DirectoryIndex website.html

我还将index.html更改为website.html,现在使用website.html而非index.html访问网站,除了无法加载css或js文件外,仍然可以正常工作。

这可以使用.htaccess文件解决吗?如果是这样,我可以添加什么来使其工作?欢迎使用其他解决方案,但应注意我没有root访问权限

的index.html

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <meta name="description" content="" />
  <meta name="author" content="" />
  <!--[if IE]>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<![endif]-->

  <title>Light Wave Template | DesignBootstrap</title>
  <!-- BOOTSTRAP CORE CSS -->
  <link href="main-site/css/bootstrap.css" rel="stylesheet" />
  <!-- CUSTOM CSS -->
  <link href="main-site/css/style.css" rel="stylesheet" />
  <!-- HTML5 Shiv and Respond.js for IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>

<body>
  <!-- HEADER SECTION START-->
  <section id="header">
    <div class="container">

      <div class="row text-center">

        <div class="col-lg-8 col-lg-offset-2 col-md-8 col-md-offset-2 col-sm-8 col-sm-offset-2 col-xs-12">
          <h1>Light Wave Template </h1>
          <p>
            <strong>6 Style </strong> Versions
          </p>
          <h4>Click on the image to see demos</h4>
        </div>

      </div>
    </div>

  </section>
  <!-- HEADER SECTION END-->
  <!-- PREVIEW SECTION START-->
  <section id="preview">
    <div class="container">
      <div class="row text-center">

        <div class="col-lg-6 col-lg-offset-3 col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2 col-xs-12 ">
          <h1>SEE DEMOS</h1>
          <h3> <a href="help-docs/index.html" target="_blank">See Document</a></h3>
        </div>

      </div>
      <div class="row">

        <div class="col-lg-6 col-md-6 col-sm-6">
          <div class="preview-wrapper">
            <a href="template/blue.html" target="_blank">
              <img src="main-site/img/previews/1.png" class="img-responsive" alt="" />
              <hr />
              <p>
                Blue Color Version ( With slider background )
              </p>
            </a>
          </div>


        </div>
        <div class="col-lg-6 col-md-6 col-sm-6">
          <div class="preview-wrapper">
            <a href="template/green.html" target="_blank">
              <img src="main-site/img/previews/2.png" class="img-responsive" alt="" />
              <hr />
              <p>
                Green Color Version ( With slider background )
              </p>
            </a>
          </div>


        </div>
        <div class="col-lg-6 col-md-6 col-sm-6">
          <div class="preview-wrapper">
            <a href="template/red.html" target="_blank">
              <img src="main-site/img/previews/3.png" class="img-responsive" alt="" />
              <hr />
              <p>
                Red Color Version ( With slider background )
              </p>
            </a>
          </div>


        </div>
        <div class="col-lg-6 col-md-6 col-sm-6">
          <div class="preview-wrapper">
            <a href="template/yellow.html" target="_blank">
              <img src="main-site/img/previews/4.png" class="img-responsive" alt="" />
              <hr />
              <p>
                Yellow Color Version ( With slider background )
              </p>
            </a>
          </div>


        </div>
        <div class="col-lg-6 col-md-6 col-sm-6">
          <div class="preview-wrapper">
            <a href="template/solid-black.html" target="_blank">
              <img src="main-site/img/previews/5.png" class="img-responsive" alt="" />
              <hr />
              <p>
                Black Background Version ( With solid background )
              </p>
            </a>
          </div>


        </div>
        <div class="col-lg-6 col-md-6 col-sm-6">
          <div class="preview-wrapper">
            <a href="template/solid-red.html" target="_blank">
              <img src="main-site/img/previews/6.png" class="img-responsive" alt="" />
              <hr />
              <p>
                Green Background Version ( With solid background )
              </p>
            </a>
          </div>


        </div>
      </div>

    </div>
  </section>
  <!-- PREVIEW SECTION END-->
  <!-- YES SECTION START-->
  <section id="yes">
    <div class="overlay">
      <div class="container">
        <div class="row text-center">
          <div class="col-lg-12 col-md-12">
            <span class="text-yes">Yes , You heard right !
                            <br />
                            its'free and with documentation</span>
          </div>

        </div>

      </div>
    </div>
  </section>
  <!-- YES SECTION END-->

  <!-- BOTTOM SECTION START-->
  <section id="bottom">
    <div class="container">

      <div class="row text-center">

        <div class="col-md-12">
          <h3>Want Some More ?</h3>
          <h4>EXPLORE : DesignBootstrap.com</h4>
        </div>
      </div>
      <div class="row text-center">

        <div class="col-md-12 ">
        </div>
      </div>
    </div>
  </section>
  <!-- BOTTOM SECTION END-->
  <!-- FOOTER SECTION START-->
  <footer>
    <div class="container">
      <div class="row text-center">
        <div class="col-md-12">
          &copy; 2015 <a href="http://www.designbootstrap.com/" target="_blank">DesignBootstrap.com </a>
        </div>
      </div>
    </div>
  </footer>
  <!-- FOOTER SECTION END-->
  <!-- JAVASCRIPT FILES PLACED AT THE BOTTOM TO REDUCE THE LOADING TIME -->
  <!-- CORE JQUERY SCRIPTS -->
  <script src="main-site/js/jquery-1.11.1.js"></script>
  <!-- BOOTSTRAP SCRIPTS -->
  <script src="main-site/js/bootstrap.js"></script>
</body>

</html>

2 个答案:

答案 0 :(得分:1)

尝试在主站点之外创建新目录并将文件移动到该目录。这可能会解决您遇到的问题。

听起来文件或目录所有权可能存在问题,但无法看到它,我不太确定。

答案 1 :(得分:1)

除了Brandon的回答,我发现实际的问题是我复制的目录没有与之关联的权限。创建临时目录后,我注意到该文件夹​​具有权限755

ls -ld tempdir
drwxr-xr-x 2 aaa111 student 4096 Feb 21 18:34 tempdir

而其他文件夹只有权限700

要修复,我运行了这个命令:

find main-site template help-docs -type d | xargs chmod 755

现在一切正常