CodeIgniter Forums
link static html pages without creating extra contorllers, possible - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: link static html pages without creating extra contorllers, possible (/showthread.php?tid=28669)



link static html pages without creating extra contorllers, possible - El Forum - 03-18-2010

[eluser]basementDUDE[/eluser]
I am trying to link few static html page in CI without creating new controllers.

I add this code to my welcome view
<a href="aboutUs.html">

but I do not want to create ANY controller to handle that URI.(sounds lazy, right?)

so, I place the aboutUs.html page in the root of CI.

CI does load the page, however, I also get a 404 error as well.

any suggestions?


link static html pages without creating extra contorllers, possible - El Forum - 03-18-2010

[eluser]Maglok[/eluser]
How can you have both a 404 error and let it load?

You have two choices. You can put it outside of CI and reference it like that, then you have to put it on the same level as the application dir. Reference with the base_url() function of CI.

The other choice is load it from within CI but that does require extra code.

In my latest project I do have a way to deal with static pages. I just save the title, path and content to the database and have a controller load that page.


link static html pages without creating extra contorllers, possible - El Forum - 03-18-2010

[eluser]Zeeshan Rasool[/eluser]
@Maglok, agreed.
You can save all of your static pages in db and just a single controller function can call all these pages with passing any param.


link static html pages without creating extra contorllers, possible - El Forum - 03-18-2010

[eluser]Lima[/eluser]
if you are using .htaccess file, just add exception in that file

default .htaccess look like this (base on ci user guide)
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

if you want browser access aboutUs.html on root public_html just add the exception in .htaccess file
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|aboutUs\.html)
RewriteRule ^(.*)$ /index.php/$1 [L]

or put all static page on one directory under root public html, so you just add exception for that directory (ex: static)
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|static)
RewriteRule ^(.*)$ /index.php/$1 [L]

one more thing.
on html code you must use "/" so browser always call aboutUs.html from root directory.
Code:
<a href="/aboutUs.html">About Us</a>
or
<a href="&lt;?php echo base_url() ?&gt;aboutUs.html">About Us</a>
hope this help you.


link static html pages without creating extra contorllers, possible - El Forum - 03-18-2010

[eluser]sophistry[/eluser]
site_migrate in the wiki (link in my sig) helps you treat static pages like views and avoid building controller functions for each page.


link static html pages without creating extra contorllers, possible - El Forum - 03-18-2010

[eluser]tomcode[/eluser]
You can use the following Rewrite Rule:

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


Now You can place any static file, even in subfolders, if a page does not exist Your CI installation is called.

I use this also rule as my standard for taking out the index.php


link static html pages without creating extra contorllers, possible - El Forum - 03-19-2010

[eluser]basementDUDE[/eluser]
thanks guys for those valuable suggestions.


link static html pages without creating extra contorllers, possible - El Forum - 03-19-2010

[eluser]basementDUDE[/eluser]
[quote author="Zeeshan Rasool" date="1268922218"]@Maglok, agreed.
You can save all of your static pages in db and just a single controller function can call all these pages with passing any param.[/quote]
save static html page in db...
how do you handle those wired punctuation such as "" // ?
or you save them as binary file?