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

本地部署Drupal网站仅能访问首页,其他页面报404错误求助

Fixing Drupal 404 Errors (Only Homepage Loads) on Local Apache

Hey there, let’s troubleshoot why your local Drupal site only loads the homepage and throws 404s for every other page. This is one of the most common hiccups with local Apache setups, so let’s walk through the key fixes step by step:

1. Enable Apache’s mod_rewrite Module

Drupal relies on this module to handle "clean URLs" (the pretty, user-friendly URLs like /node/1 instead of /?q=node/1). Here’s how to turn it on:

  • Open your Apache configuration file (httpd.conf — usually found in XAMPP/apache/conf or WAMP/bin/apache/apacheX.X.X/conf).
  • Look for the line: #LoadModule rewrite_module modules/mod_rewrite.so
  • Remove the # at the start to uncomment it, save the file, and restart Apache.

2. Allow .htaccess Files to Work

Apache blocks .htaccess rules by default for security, but Drupal needs them to route URLs correctly. Update your site’s directory settings:

  • In httpd.conf, find the <Directory> block that points to your Drupal site’s root folder (e.g., <Directory "C:/xampp/htdocs/your-drupal-site">).
  • Change AllowOverride None to AllowOverride All.
  • Save the file and restart Apache again.

3. Enable Clean URLs in Drupal

Even if your server is set up right, Drupal might not have clean URLs enabled yet. To check:

  • Visit localhost/your-drupal-site/?q=admin/config/search/clean-urls (replace your-drupal-site with your actual site folder name).
  • If the option to enable clean URLs is available, check the box and save the settings.

4. Verify the .htaccess File

Make sure your Drupal root directory has a valid .htaccess file (it’s included in the default Drupal download). If it’s missing or modified:

  • Grab a fresh copy from the Drupal installation package and paste it into your site root.
  • Double-check the RewriteBase line inside the file: it should match your site’s path relative to localhost. For example, if your site is at localhost/drupal, set RewriteBase /drupal/.

If You’re Still Stuck

Check Apache’s error logs (usually in XAMPP/apache/logs/error.log or similar) — they’ll have specific details about what’s causing the 404s, which can help narrow down the issue further.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 08:30:34