You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在HTML中展示托管域名网站特定目录(文件夹)的内容?

Fixing Directory Listing for Your Hosted Website

Hey there! I’ve dealt with this exact frustration before—having a folder full of files but being stuck without automatic directory listing (instead of manually linking every single one). Let’s break down the most common fixes to get this working, since you know it works locally:

1. Check Your Web Server’s Directory Listing Module

Most web servers need a specific module enabled to show directory contents:

  • Apache: Make sure the mod_autoindex module is enabled (most hosted environments have this on by default, but it never hurts to confirm). Then, add this line to a .htaccess file in the target directory:
    Options +Indexes
    
    If there’s already an Options line in the .htaccess, make sure it doesn’t include -Indexes (that disables listing).
  • Nginx: You’ll need to add the autoindex directive in your server or location config for the directory:
    location /your-target-directory/ {
        autoindex on;
        # Optional: Makes file sizes easier to read
        autoindex_exact_size off;
    }
    
    If you’re on a shared host, you might need to reach out to support to adjust this, or check if they offer a control panel setting for it.

2. Override Default Blocking in .htaccess

Many hosting providers default to disabling directory listing site-wide via a root .htaccess file (with Options -Indexes). To override this for your specific folder, create a new .htaccess file inside the directory you want to list, and add the Options +Indexes line as mentioned above. This takes precedence over the root config.

3. Remove or Rename Default Index Files

If your directory has a default index file (like index.html, index.php, index.htm), the server will load that file instead of showing the directory listing. If you don’t need that index file, rename it (e.g., to index-old.html) or move it temporarily—this should trigger the directory listing to appear.

4. Check Your Hosting Control Panel Settings

Managed hosts (like cPanel, Plesk, or site builders) often have a dedicated setting for directory indexing. Look for options like Directory Indexing, Show Indexes, or Folder Listing in your hosting dashboard. Toggle it on for the specific folder, and that should do the trick without messing with config files.

Start with the simplest checks first—like verifying there’s no default index file in the folder, then adding the .htaccess line. If those don’t work, check your hosting control panel or reach out to your provider’s support (they might have locked down some settings).

内容的提问来源于stack exchange,提问作者Nóra Török

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 07:48:36