link static html pages without creating extra contorllers, possible

#1
[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?

#2
[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.

#3
[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.

#4
[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.

#5
[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.

#6
[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

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

#8
[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?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.