Welcome Guest, Not a member yet? Register   Sign In
code igniter css .htaccess
#1

[eluser]babyboss[/eluser]
Hello, I have multiple applications under application folder
the structure looks like the following
/codeigniter/system/application/application1
/codeigniter/system/application/application2
....
....

I have a css folder under
/codeigniter

According to some of my google results, I need to have following lines in my .htaccess file

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|captcha|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

I put this .htaccess file under /codeigniter

After all this, my apache server does not seem to recognize any of my application at all.
After deletion of .htaccess file, the server recognizes my application, but the stylesheet rules are not applied.

Thank you very much.
#2

[eluser]OverZealous[/eluser]
You'll need to spend a little time reading about how to properly use the .htaccess file.

Were you using a .htaccess file at all before? How are your multiple applications accessed (meaning, are you using multiple index files?)

If you weren't using a .htaccess file before, then no remapping was being done, and the error is how you are linking to your CSS file. If you are hard-coding the path for the CSS file as "css/style.css", then this happens:

If you are at the root page, example.com/codeigniter/index.php, the relative path "css/style.css" becomes example.com/codeigniter/css/style.css.

However, if you are at example.com/codeigniter/index.php/some/other/path, the css path becomes example.com/codeigniter/index.php/some/other/style/css.

The solution to this is to either a) use an absolute path ("/codeigniter/css/style.css", or b) use the .htaccess file, but then you have to change your CodeIgniter configuration to the correct base url (which is now http://www.example.com/codeigniter/), and also replace any and all url references with site_url('path/to/resource'). This includes links, JavaScript files, and css files (site_url('css/style.css')).

Option (b) is more "correct", because you end up with cleaner URLs that contain no 'index.php'. You will have to figure out how to make both applications work, however. You might need to set up a second set of mod_rewrite rules to redirect the second app.
#3

[eluser]babyboss[/eluser]
I have read some more materials on .htaccess. I am kind of confused.
Some more questions,
1.for editing the base url, do I edit the config file under myApplication/config/config.php
2.with .htaccess file, do I need to delete the index.php file under the root folder?
3.Originally, index.php under the root folder is used to direct webpage to myApplication. If index.php is deleted, do I need to do write some codes in .htaccess so that it can direct webpages to myApplication.
#4

[eluser]OverZealous[/eluser]
Some of what you are asking is answered in the CodeIgniter manual already, scroll down to "Removing the index.php file".

1) Yes
2) No
3) n/a

It's helpful to understand what mod_rewrite is really doing: All it is doing is taking a requested URL ('codeigniter/some/link') and rewriting it as a different URL ('codeigniter/index.php/some/link'). Apache (your webserver) then loads the second URL as if it was originally requested.

This is why you need to leave index.php, because it actually is still being used!

Finally, if you are using one CodeIgniter to run multiple applications, you'll need to make two copies of index.php (ex: index.php and otherapp.php), and add 'otherapp\.php' to the exclusion list in your .htaccess. The first application is accessed using 'codeigniter/whatever', and the second using 'codeigniter/otherapp.php/whatever'. If you get bored, you might play around and figure out how to replace the /otherapp.php/ with /otherapp/, but I'll leave that up to you.




Theme © iAndrew 2016 - Forum software by © MyBB