Welcome Guest, Not a member yet? Register   Sign In
Migrating a static HTML website to CodeIgniter
#1

[eluser]Unknown[/eluser]
I'm beginning to integrate CodeIgniter into a static HTML website. I did a bit of research on the methods other people had employed, but in the end they all seemed like more effort than should be necessary.

Here's the "Site Migrate" entry on the CI Wiki:
<a href="http://codeigniter.com/wiki/site_migrate/">http://codeigniter.com/wiki/site_migrate/</a>

Rather than doing all that, I decided to edit my .htaccess file and use mod_rewrite to handle things. Here's what it looks like:

Quote:RewriteEngine on
RewriteRule ^ci/* / [R,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L]
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]


How it works, line by line:

Quote:RewriteEngine on
Tell Apache to use the RewriteEngine

Quote:RewriteRule ^ci/* / [R,L]
If someone tries to directly access files in my CodeIgniter directory (ci is the directory name), redirect to the site root. [R, L] = Reload, Stop evaluating rules.

This rule is necessary because in the next rule I stop evaluating rules when someone enters the URL of a file that exists on the server, and the last rule is the one that says "run everything through CodeIgniter." So, if someone were to enter the URL of a CodeIgniter file it would display it directly, without running it through CI. We don't want that.

Quote:RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L]
Check to see if the file requested actually exists on the server, if so then display it and stop evaluating Rewrite rules. All my old HTML files that have not yet been replaced by CodeIgniter are served up based on this rule.

Quote:RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
See <a href="http://ellislab.com/codeigniter/user-guide/general/urls.html">Removing the index.php file</a>

I found this <a href="http://corz.org/serv/tricks/htaccess2.php">.htaccess tips and tricks</a> page to be helpful in understanding mod_rewrite.

What are your thoughts on this method?
#2

[eluser]sophistry[/eluser]
i posted a studious and trenchant reply to this thread yesterday and now it is gone.

what happened?
#3

[eluser]Unknown[/eluser]
Is this the reply you're referring to?

<a href="http://ellislab.com/forums/viewthread/91182/#809116">http://ellislab.com/forums/viewthread/91182/#809116</a>

I've you have further comment, I'd love to hear it!
#4

[eluser]sophistry[/eluser]
oops! yes, losing my mind. i posted it to the other thread. thanks josh.

no further comment, the main idea being that site_migrate puts your static site "inside" CI and you can start melding them together easily.




Theme © iAndrew 2016 - Forum software by © MyBB