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

求助:CodeIgniter应用部署后出现307重定向问题的解决办法

Fixing CodeIgniter 307 Redirect Issue After Folder Restructuring

Hey there, let's work through this 307 redirect problem you're dealing with after moving your CodeIgniter folders into the public directory under public_html. I've debugged similar hosting setup issues before, so here are the key fixes to apply:

1. Update the Entry Point (index.php) Paths

The most common culprit here is that your main index.php file can't find the application and system folders anymore. If you moved those folders into public, you need to adjust the paths in index.php (which should be in your public_html root, or inside public—depending on your setup):

Open your index.php file and modify these lines:

// Path to the application folder
$application_folder = './public/application';

// Path to the system folder
$system_path = './public/system';

Make sure the paths match where you actually moved the folders. If index.php is inside the public folder itself, you'd use ./application and ./system instead.

2. Correct config.php Settings

Next, head to application/config/config.php and double-check these critical settings:

  • Base URL: Set $config['base_url'] to your actual domain, including the correct path if public is part of the URL. For example:
    $config['base_url'] = 'https://yourdomain.com/public/';
    
    If you want the public folder to be hidden (so your URL is just https://yourdomain.com/), you'll need to tweak your .htaccess file (more on that below).
  • Index Page: Ensure $config['index_page'] is set correctly. If you're using .htaccess to remove index.php, set it to an empty string:
    $config['index_page'] = '';
    

3. Fix .htaccess Rules

A misconfigured .htaccess is often the cause of 307 redirect loops. Here's a working rule set tailored to your folder structure:

If your index.php is in public_html/public, create or update the .htaccess in public_html (the root) to redirect all traffic to the public folder:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,R=301]

Then, inside the public folder, add another .htaccess to handle CodeIgniter's clean URLs:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

If your index.php is already in the public_html root and you moved the core folders into public, adjust the .htaccess to point to the correct index.php path.

4. Check Server Directory Permissions

Sometimes 307 redirects can happen if the server doesn't have proper access to your application or public folders. Make sure:

  • The application folder has permissions set to 755 (read/execute for everyone, write for owner)
  • The public folder also uses 755 permissions
  • Files inside these folders should be 644 (read/write for owner, read for others)

5. Verify Default Route and Controller

If the redirect is happening when accessing the root URL, check your application/config/routes.php to ensure the default route points to an existing controller:

$route['default_controller'] = 'Home'; // Make sure Home.php exists in controllers folder

If the controller file name or class name is misspelled (CodeIgniter is case-sensitive in some setups), this can trigger unexpected redirects.

After making these changes, clear your browser cache and test the site again. If the 307 issue persists, check your server's error logs—they often provide specific details about what's causing the redirect loop.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 09:54:48