0

I've installed a CodeIgniter app on an OpenLiteSpeed server, and although the script installation went smoothly, there appears to be a problem with the .htaccess redirects.

Pages only seem to work when adding "index.php" at the beginning of the URL, such as https://app.example.com/index.php/admin. If I visit https://app.example.com/admin, the site breaks.

The contents of my .htaccess file is as follows:

<IfModule mod_rewrite.c>
    RewriteEngine On

    # RewriteBase could be necessary depending on your server setup
    # RewriteBase /

    # Add this to handle requests to your CodeIgniter front controller
    RewriteCond %{REQUEST_URI} !^/(index\.php|assets|robots\.txt|favicon.ico)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]

    # Existing rules
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule !.(js|css|eot|svg|ttf|woff|woff2|map)$ index.php [L]
    RewriteCond $1 !^(index\.php|assets)
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

    # Redirect requests for favicon.ico to the actual file
    Redirect 301 /favicon.ico /assets/images/favicon.ico

    # Deny access to .env file
    <Files .env>
        Order allow,deny
        Deny from all
    </Files>
</IfModule>

Any help would be appreciated.

I tried editing the .htaccess file inline with any documentation I could find online pertaining to OpenLiteSpeed and redirects, but have had no joy so far.

3
  • What do you mean by "the site breaks" exactly? Do you simply get a 404 or some other error? Is CodeIgniter invoked? From the limited information here it sounds like either .htaccess files are not enabled and/or mod_rewrite is not enabled. If you request /favicon.ico, are you externally redirected? Commented May 12 at 12:59
  • Problem is not with with your .htaccess, you need to remove "index.php" from baseurl. Go to app/Config/App.php and remove "index.php" from baseurl or you can also set it in .env file. If you struggle, search remove index.php in Codeigniter4 Commented May 14 at 13:40
  • @Jay85 "Problem is not with with your .htaccess" - If .htaccess was "working" then they should still be able to access the URL as stated in the question (without index.php). Changing the URL format in CI simply instructs how CI generates URLs (not necessarily how CI interprets them) - which the OP will also need to do (but by the sounds of it they have already done this, since they can only get it to work by "adding "index.php" at the beginning of the URL"). Commented May 14 at 17:22

1 Answer 1

0

Try go to app/Config/App.php

Change:

public string $indexPage = 'index.php';

To:

public string $indexPage = '';

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.