I made an old CodeIgniter 2 PHP 5.6 website over 10 years ago, and am trying to restore it online; keep getting 404 errors (the first page works, tho)

I keep getting server 404 errors when trying to interact with my website: http://www.interjo.in/

my .htaccess file is as follows:

RewriteEngine On
# First add the www to URL
RewriteCond %{HTTP_HOST} ^interjo.in$ [NC]
RewriteRule ^(.*)$ http://www.interjo.in/$1 [L,R=301]

# The remove the index.php from URL
RewriteCond $1 !^(index\.php|ref_doc|media|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

in my config file, these are the first few options:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
|   http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
$config['base_url'] = 'http://www.interjo.in/';

/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';

/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string.  The default setting of 'AUTO' works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'AUTO'            Default - auto detects
| 'PATH_INFO'       Uses the PATH_INFO
| 'QUERY_STRING'    Uses the QUERY_STRING
| 'REQUEST_URI'     Uses the REQUEST_URI
| 'ORIG_PATH_INFO'  Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol'] = 'AUTO';

/*
|--------------------------------------------------------------------------
| URL suffix
|--------------------------------------------------------------------------
|
| This option allows you to add a suffix to all URLs generated by CodeIgniter.
| For more information please see the user guide:
|
| http://codeigniter.com/user_guide/general/urls.html
*/

$config['url_suffix'] = '';

For some reason the signup page is only showing up if i add /index.php?/signup at the end see here: Create Account

but if i type it WITHOUT the index.php, it shows a 404 error code, like this: https://www.interjo.in/signup

i dont understand why it’s doing that; shouldnt codeigniter 2 figure out that im calling the “signup” controller without the extra /inedx.php?/?

i’m hosting this on my synology NAS via docker (via web station and container manager)

The issue you’re encountering likely stems from either:

  1. Misconfiguration in the .htaccess file for URL rewriting.
  2. Apache module mod_rewrite not enabled on your Synology NAS setup.
  3. Incorrect URI routing settings in your CodeIgniter configuration.

Here’s how you can troubleshoot and resolve the problem step by step:


1. Check if mod_rewrite is enabled

  • Ensure the mod_rewrite module is enabled on your Apache server.
  • If you’re using Docker, verify that the web server image supports mod_rewrite.
  • To enable mod_rewrite, you can typically run the following command on the host system:
sudo a2enmod rewrite
sudo systemctl restart apache2

2. Update Your .htaccess File

Your current .htaccess file has issues. Try this revised version:

RewriteEngine On

# Redirect non-www to www
RewriteCond %{HTTP_HOST} ^interjo\.in$ [NC]
RewriteRule ^(.*)$ http://www.interjo.in/$1 [L,R=301]

# Remove "index.php" from URL
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php/$1 [L]

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

Key Points:

  • The rule RewriteCond %{REQUEST_URI} !^index\.php has been adjusted to prevent conflicts.
  • This .htaccess file ensures that www.interjo.in/signup works as expected.

3. Ensure the base_url and index_page are Configured Correctly

In your CodeIgniter config.php file:

$config['base_url'] = 'http://www.interjo.in/';
$config['index_page'] = ''; // Leave this blank to remove "index.php" from URLs

4. Verify Your Docker and Synology NAS Setup

If you’re using Docker, ensure that:

  • The web server container has permissions to access the .htaccess file.
  • The correct ports are exposed and mapped on your Synology NAS.

For example, your Docker container might require an additional --volume flag in the docker run command to bind the .htaccess file correctly.


5. Update CodeIgniter’s Routing (Optional)

Ensure that your routes.php in the application/config folder is correctly configured. For example:

$route['default_controller'] = 'welcome'; // Adjust to your default controller
$route['404_override'] = ''; // Use default 404 handling
$route['translate_uri_dashes'] = FALSE;

6. Test Apache Configuration

After making changes:

  1. Restart your Apache web server (or Docker container).
sudo systemctl restart apache2

Or, for Docker:

docker restart <container_name>
  1. Clear your browser cache and reload the page:
  • Test https://www.interjo.in/signup.

7. Debugging 404 Errors

If the problem persists:

  • Enable debugging in CodeIgniter to identify the cause of the 404 error. Update the index.php file:
define('ENVIRONMENT', 'development');
  • Check Apache error logs for details:
sudo tail -f /var/log/apache2/error.log

Let me know if this helps or if you’d like assistance troubleshooting further!