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

CodeIgniter 3 + XAMPP 环境下无法移除URL中的index.php求助

Fixing CodeIgniter index.php Required Issue on XAMPP Subdirectory

Hey, I see you've already dug through several posts and tried basic configurations, but that 404 error when skipping index.php is a common snag with subdirectory deployments. Let's work through the fixes one by one:

  • Update Your base_url Configuration
    Your current $config['base_url'] points to http://localhost, but your site lives in the /mysite subdirectory. This misalignment throws off CodeIgniter's routing logic. Update it to:

    $config['base_url'] = "http://localhost/mysite/";
    
  • Adjust .htaccess with RewriteBase
    Apache needs explicit guidance on the base directory for rewrite rules when working in a subfolder. Modify your .htaccess file (make sure it’s placed in the same folder as CodeIgniter’s index.php) to include RewriteBase and tweak the final rule:

    RewriteEngine on
    RewriteBase /mysite/
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    

    The key changes here are adding RewriteBase /mysite/ and removing the ? in the RewriteRule—CodeIgniter doesn’t require that query string format for routing.

  • Verify .htaccess Location
    Double-check that your .htaccess file is placed directly in htdocs/mysite/ (the same directory as index.php). If it’s in the root htdocs folder or another location, the rewrite rules won’t apply to your site.

  • Enable AllowOverride in Apache's httpd.conf
    You’ve turned on the rewrite module, but Apache might still be blocking .htaccess rules in your subdirectory. Open httpd.conf and find the <Directory> block for your site’s folder (or the root htdocs folder). Change AllowOverride None to AllowOverride All:

    <Directory "C:/xampp/htdocs/mysite">
        AllowOverride All
        Require all granted
    </Directory>
    

    Don’t forget to restart Apache after making this change—the configuration won’t take effect until you do.

  • Try a Different uri_protocol
    Your current setting REQUEST_URI works for most environments, but switching to AUTO can help CodeIgniter correctly parse the URL in some cases. Update config.php:

    $config['uri_protocol'] = 'AUTO';
    
  • Confirm mod_rewrite is Actually Enabled
    To be 100% sure the rewrite module is active, create a file named info.php in your mysite folder with this content:

    <?php phpinfo(); ?>
    

    Visit http://localhost/mysite/info.php and search for "mod_rewrite". If it doesn’t show up, go back to httpd.conf and confirm the line LoadModule rewrite_module modules/mod_rewrite.so is uncommented, then restart Apache again.

After making all these changes and restarting Apache, test accessing http://localhost/mysite/newpage—it should load without needing index.php now.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 21:29:08