Search code examples
codeignitercodeigniter-3backslashtrailing-slash

Putting Slash / in the URL in Codeigniter breaks the page style/images etc


My website is working fine. All controllers works fine unless I put a slash at the end the pages broke.

Here is oringal URL: Saaf.Pk

But when I put a slash at the end, style & images broked: Here

I know the problem is that URL path got changed. But what's the general solution for this situation?

My .htaccess

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

Solution

  • are you using base_url to define every image, js, css etc?

    example img

    <img src="<?=base_url('assets/uploads/cms/') . $cms->logo_2?>" alt="Logo">
    

    example js

    <script src="<?=base_url('assets/plugins/jquery-3.3.1/jquery.min.js')?>"></script>
    

    example css

    <link href="<?=base_url('assets/guide/css/hopscotch.css')?>" rel="stylesheet"/>