Pragnesh Chauhan
Pragnesh Chauhan

Reputation: 8476

Codeigniter V4 not loading public resources

I am using CodeIgniter 4.1.3.

below is my .htaccess

#Options All -Indexes

<IfModule mod_rewrite.c>
#Options +FollowSymlinks
RewriteEngine On
# RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]

RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>


ServerSignature Off

options all and followSymlinks not supported on server. Working fine on localserver

Front page is loaded but it is not loading css,javascript and image from public directory giving 404 error.

not sure what need to be change.

Upvotes: 0

Views: 1215

Answers (2)

Virender Kumar
Virender Kumar

Reputation: 182

Options All -Indexes 
Options +FollowSymlinks

works well on apache but if your server is centos then use this

Options -Indexes 
Options +SymLinksIfOwnerMatch

Upvotes: 0

RavinderSingh13
RavinderSingh13

Reputation: 133428

With your shown samples, please try following htaccess Rules file. Make sure to place this in your root directory. Also make sure to clear your browser cache before testing your URLs.

Options -Multiviews
<IfModule mod_rewrite.c>
#Options +FollowSymlinks
RewriteEngine On
RewriteBase /public/

RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
   
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php/$1 [L,NC,QSA]

</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>

ServerSignature Off

JS/CS rewrite/redirect: You may need to use base tag to fix your js and other relative resources. If you are linking js files using a relative path then the file will obviously get a 404 because its looking for URL path. for example if the URL path is /file/ instead of file.html then your relative resources are loading from /file/ which is not a directory but rewritten html file. To fix this make your links absolute or use base tag. In the header of your webpage add this <base href="/"> so that your relative links can load from the correct location.

Upvotes: 1

Related Questions