Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter Static content
#1

[eluser]pestilence[/eluser]
Hello All,
Here is a quick dirty hack to make your codeigniter work nicely with static content (hey you know there are times static pages are required without the fuss of controllers, models etc).
So say that you want all your html requests to be served as static content here is a nice .htaccess file to implement this:
Code:
RewriteEngine on
RewriteCond %{REQUEST_URI} !/static/
RewriteRule ^(.+)\.html$ /static/$1.html [L]
RewriteCond $1 !^(index\.php|images|robots\.txt|static)
RewriteRule ^(.*)$ /index.php/$1 [L]

This will redirect all of your static requests (.html pages) to the static directory, so you simply only need to have your static pages inside the static directory and you are good to go Smile
#2

[eluser]pestilence[/eluser]
Further playing..
To have your css nicely organized under modules (in case you are using matchbox)
:
Code:
RewriteCond %{REQUEST_URI} !modules/(.*)/css/(.*)$
RewriteRule /(.+)/css/(.+)\.css$ /system/application/modules/$1/css/$2.css [L]

Put the above before the lines of the previous post, and make sure you have a valid css directory under your:
Code:
modules/module_name/
directory.
Now you can include any css like:
http://yourhost/module_name/css/module_name.css
#3

[eluser]pestilence[/eluser]
Forgot to add as well, that if you modify the above make sure your rewrite CI rules to ignore requests made for static content or css files:
Code:
RewriteCond $1 !^(index\.php|images|robots\.txt|static|.*\.css)




Theme © iAndrew 2016 - Forum software by © MyBB