0

My application folder structure is like

root>assets>css+fonts+frontend+images+js

but I can't access the contents in the assets folder. They always show "404 page not found".

As an example, mysite.com/assets/frontend/page.css shows the error. At the same time, mysite.com/assets/css/bootstrap.min.css shows the error.

My .htaccess file is

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
3
  • Did you set your base url and autoload the url helper? Commented Feb 9, 2017 at 20:27
  • Yes i added base url and autoload the url helper. The code works fine in my development server(Easy PHP Dev Server) but not in my web hosting. Commented Feb 9, 2017 at 20:32
  • because you're most likely using relative links. When you are using mod_rewrite you will need to either use absolute links, a forward slash in front or the base tag in the head section. Commented Feb 9, 2017 at 21:18

1 Answer 1

2

Add this rule to your htaccess rewrite:

RewriteCond $1 !^(index\.php|assets)

The issue is that when you remove index.php from your project, what you are actually doing is rewriting anything at that level to point to index.php...

If index.php wasn't being blocked you would see e.g. http://localhost/index.php/assets/ etc...

You need to adjust the rewrite to ignore your assets folder with !^ (ignore starting with) then assets, so you can access that folder

You can check it working / not working by going to mysite.com/assets/css/bootstrap.min.css in your browser and it saying it doesn't exist (with your current .htaccess file)

The rewrite you have RewriteRule ^(.*)$ index.php/$1 [L] is doing this...

^ is the start of string (uri) ( is the start of regex group .* is the everything at first URI level ) is the end of regex group $ is the end of string

You are then telling it to effectively look past index.php/ then continue looking at $1

The rule I have given you is adding exceptions to what you already have to ignore certain URI segments

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.