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

CodeIgniter重定向无报错但页面未切换问题求助

Troubleshooting CodeIgniter URL Rewrite Issue: URL Updates But Page Doesn't Change

Hey there, let's tackle this frustrating issue you're having with CodeIgniter. It's odd that the URL updates to localhost:8888/my_site/contact but the content stays the same—let's walk through the most likely causes and fixes step by step:

1. Verify CodeIgniter Core Configurations

First, double-check your application/config/config.php settings, since these are often the root of rewrite problems:

  • Ensure $config['base_url'] is set correctly to your site's root, including the trailing slash:
    $config['base_url'] = 'http://localhost:8888/my_site/';
    
  • Make sure $config['index_page'] is empty (we want to remove index.php from URLs entirely):
    $config['index_page'] = '';
    

2. Fix Your .htaccess Rules for Subdirectories

Even though your .htaccess is loading, the rewrite rules might not be tailored to your subdirectory setup. Try this standard CodeIgniter .htaccess for subdirectories:

RewriteEngine On
# Set the base path to your subdirectory
RewriteBase /my_site/

# Ignore existing files/directories so they load normally
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Route all other requests through index.php
RewriteRule ^(.*)$ index.php/$1 [L]

Also, confirm your Apache configuration allows .htaccess overrides—look for AllowOverride All in your httpd.conf or virtual host file for the my_site directory (this ensures your rewrite rules are actually applied).

3. Validate Routes & Controller Setup

  • Check application/config/routes.php to confirm you have a proper route for contact:
    $route['contact'] = 'contact/index';
    
    (This assumes your controller is named Contact.php with an index() method.)
  • Confirm your controller follows CodeIgniter's naming rules:
    • Filename must be uppercase: Contact.php
    • Class name must match the filename (uppercase first letter):
      class Contact extends CI_Controller {
          public function index() {
              $this->load->view('contact_view'); // Make sure this view file exists too!
          }
      }
      

4. Test Direct Controller Access

Try accessing the contact page directly with index.php to isolate the issue:
http://localhost:8888/my_site/index.php/contact

  • If this loads correctly: The problem lies with your .htaccess rewrite rules or server mod_rewrite setup.
  • If this doesn't load: The issue is with your controller, route, or view—double-check those files exist and have no syntax errors.

5. Rule Out Browser Caching

Sometimes browser cache can trick you into thinking the page isn't updating. Try:

  • Force-refreshing the page with Ctrl + F5 (Windows/Linux) or Cmd + Shift + R (Mac)
  • Clearing your browser's cache entirely

6. Check for Frontend JavaScript Interference

If your contact link is handled by JavaScript, make sure there's no code blocking the default navigation behavior. Look for event.preventDefault() in your JS files that might be stopping the link from loading the new page without replacing the content properly.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 11:15:00