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

添加.htaccess后XAMPP及线上网站无法自动加载index.php求助

Fixing Auto-Load of index.php After Adding .htaccess Rewrite Rules

Hey there, let's break down why your site isn't automatically loading index.php when you visit the /ChoiceGelatin directory, and how to fix it quickly.

The Root Cause

Your current Rewrite rules work great for non-directory requests (like turning /about into /about.php), but they don't handle the default directory index behavior. When you visit a directory URL, Apache relies on the DirectoryIndex setting to know which file to load by default—if this isn't explicitly set, or if your host's default config doesn't prioritize index.php, it won't kick in automatically.

Step-by-Step Fix

  1. Explicitly Set the Directory Index
    Add this line at the very top of your .htaccess file. This tells Apache to always look for index.php first when accessing a directory:

    DirectoryIndex index.php
    
  2. Keep Your Existing Rewrite Rules (They're Fine!)
    Your current Rewrite setup doesn't conflict with the directory index once you add the above line. Here's your full, updated .htaccess for reference:

    DirectoryIndex index.php
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php [NC,L]
    

Why This Works

When you visit /ChoiceGelatin, Apache now knows to check for index.php in that directory first. Since your Rewrite rules only trigger when the request isn't a directory (!-d condition), they won't interfere with this default behavior. Manually visiting /ChoiceGelatin/index.php worked before because you were directly referencing the file—this fix makes that happen automatically.

If you still run into issues, double-check that your web host allows .htaccess to override the DirectoryIndex setting (most shared hosts do, but some require AllowOverride All in their server config).

内容的提问来源于stack exchange,提问作者ArabianMaiden

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:40:58