添加.htaccess后XAMPP及线上网站无法自动加载index.php求助
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
Explicitly Set the Directory Index
Add this line at the very top of your.htaccessfile. This tells Apache to always look forindex.phpfirst when accessing a directory:DirectoryIndex index.phpKeep 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.htaccessfor 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

