本地部署Drupal网站仅能访问首页,其他页面报404错误求助
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 inXAMPP/apache/conforWAMP/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 NonetoAllowOverride 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(replaceyour-drupal-sitewith 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
RewriteBaseline inside the file: it should match your site’s path relative to localhost. For example, if your site is atlocalhost/drupal, setRewriteBase /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

