【问题标题】:Can a localhost directly lead to an html file?本地主机可以直接导致html文件吗?
【发布时间】:2022-02-18 13:12:56
【问题描述】:

这里是 HTML 新手。我使用 html 文件设置了我的本地主机,但我必须使用 localhost:8080/filename.html 访问它。有没有办法直接用 localhost:8080 访问它?

【问题讨论】:

标签: html node.js npm localhost


【解决方案1】:
  1. 编辑 .htaccess 文件

  2. 将以下代码粘贴到文件的开头,将“filename.html”行更改为您希望用作网站主页的页面。

    DirectoryIndex first.html

  3. 您还可以设置多个索引文件作为您网站的首页。

    DirectoryIndex home.html index.html index.php

【讨论】:

  • .htaccess 文件将从左到右读取并选择第一个可用页面。例如,使用以下代码,文件home.htmlindex.htmlindex.php 将被添加为网站的索引页面。服务器会寻找 home.html 文件,如果没有找到会继续寻找index.html 文件等DirectoryIndex home.html index.html index.php
【解决方案2】:

根据您的操作环境,您应该能够使用 htaccess 文件完成此操作。在你的根目录中创建一个名为 .htaccess 的文件

添加此代码:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
DirectoryIndex filename.html

【讨论】:

  • 问题标记为 node.js 而不是 apache
  • 这里使用 mod_rewrite 似乎完全是多余的
猜你喜欢
  • 1970-01-01
  • 2011-07-07
  • 1970-01-01
  • 1970-01-01
  • 2011-07-07
  • 2016-10-23
  • 1970-01-01
  • 2011-04-17
  • 1970-01-01
相关资源
最近更新 更多