Haider Saeed
Haider Saeed

Reputation: 287

CodeIgniter not loading assets due to .htaccess rewrite for subdirectory

Here is the site, I'm working on: example.com My all Codeigniter files are in sub directory "dir1".

For my root directory, here the .htaccess file:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
RewriteCond %{REQUEST_URI} !^/dir1/ 
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /dir1/$1 
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 

RewriteRule ^(.*)$ dir1/index.php?$1 [L]

and Here's my "wework" directory's .htaccess file: (codeigniter files are here)

RewriteEngine on

RewriteBase /dir1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

if I change my base url from example.com to example.com/dir1 then it works fine but its adds "dir1" sub directory name in all the url's. Please help me how to load my assets. Thanks

Edit:

my "assetss" folder is in "dir1" directory. but when I load my site in browser and view source in browser it shows :

<link rel="stylesheet" type="text/css" href="http://example.com/assetss/css/style.css"/>

but my assets are here : example.com/dir1/assetss

I'm using godaddy server and my domain is configured to upload my files into "dir1" directory. Please help me. Many Many thanks again

Upvotes: 2

Views: 838

Answers (1)

Jon Lin
Jon Lin

Reputation: 143946

At the end of your first rule, try adding a [L], then for the second rule, include the same !-f and !-d conditions:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
RewriteCond %{REQUEST_URI} !^/dir1/ 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /dir1/$1 [L]

RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ dir1/index.php?$1 [L]

Upvotes: 1

Related Questions