XAMPP中出现‘请求的URL未找到’错误,已尝试其他方案仍未解决
Hey there, I’ve dealt with this exact headache multiple times setting up CodeIgniter projects on XAMPP—let’s walk through the fixes that usually crack it, since you’ve already knocked out the basic config tweaks.
1. Add a Proper .htaccess File
First, create (or update) a .htaccess file in your new project’s root directory (right alongside the application and system folders). Paste this code into it:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L]
This tells Apache to route all non-file/non-directory requests through index.php without showing it in the URL.
2. Turn On Apache’s mod_rewrite Module
XAMPP often has this disabled by default:
- Open your XAMPP control panel, click "Config" next to Apache, then select
httpd.conf. - Find the line
#LoadModule rewrite_module modules/mod_rewrite.soand delete the#at the start. - Save the file and restart Apache from the XAMPP control panel.
3. Update AllowOverride in httpd.conf
Apache might be ignoring your .htaccess unless you explicitly allow it:
- In the same
httpd.conffile, locate the<Directory>block for your XAMPP htdocs folder (usually something like<Directory "C:/xampp/htdocs">). - Change
AllowOverride NonetoAllowOverride All. - Save and restart Apache again—this step is easy to miss, but it’s critical.
4. Tweak the uri_protocol Setting
You tried AUTO, but that doesn’t always play nice with XAMPP. Swap it for one of these in your config.php:
$config['uri_protocol'] = 'REQUEST_URI'; // OR $config['uri_protocol'] = 'PATH_INFO';
Save the file and test your URL again.
5. Double-Check Folder Structure & Permissions
- Make sure your new project lives directly inside
htdocs(e.g.,C:/xampp/htdocs/my-new-ci-project), so your base URL ishttp://localhost/my-new-ci-project/. - On Windows, permissions are usually fine, but if you’re on Linux/WSL, run
chmod -R 755 /path/to/your/projectto ensure Apache can read your files.
6. Avoid Conflicts With Other CI Projects
Since you have multiple CI projects, confirm each has its own .htaccess file—don’t share one across all projects. Each project’s rewrite rules should only apply to its own directory.
After working through these steps, try accessing a controller method without index.php (like http://localhost/my-new-ci-project/welcome/index). It should load without the 404 error now!
内容的提问来源于stack exchange,提问作者Bad Programmer




