Codeigniter: how to serve static html pages in codeigniter context - codeigniter

Hi all
I want to serve some static html pages in codeigniter context. I dont want to bypass the index.php file in the base_url.
But when I user the call to the HTML file, it dispays the 404 error page.
I appreciate any help for this topic from guys who already solving this problem . Thanks for all in advance
I want to precise this elements:
my real problem is to serve PDF file for users to display in the browser only an not to save the PDF file. So I convert the PDF to HTML Files. The output is a directory with HTML files linked betwen them and ther images/button, CSS, js for navigation
when i put this HTML-OUTPUT in ci\Docs\HTML1 directory I can access it whith this URL localhost/ci/docs/html1/index.htm.
But where i use localhost/ci/index.php/docs/html1/index.htm I get A 404 error page.
So I moved The HMLT1 directory to the Application\views directory. And i stil have the same error. My .htacces look like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
Thanks Guys for your help

Create the static HTML file as a view and then just load the view:
$this->load->view('static.html');
You can then access this file as a normal controller. It all depends on how you have set up your .htaccess as well.

For me I just add a folder name for my static html pages into the .htaccess to exclude it from regexp like below, and it work. Just to exclude it from rewrite URL to index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|sitemap\.xml|static-html)
RewriteRule ^(.*)$ index.php/$1 [L]

$route['your-page-url'] = "/page/message/your-page-url";
In your Page controller function:
public function message($page = 'your-page-url')
{
$data['title']= 'Your Page Title';
$this->load->view('/header',$data);
$this->load->view('pages/your-page-url');
$this->load->view('/footer');
}

Related

How can I open my page without .html address?

I am a beginner, so sorry for this question.
the main page name is: index.html
and a second page is for example second.html
The issue:
I can just open it on the browser by using the full name includes .html means:
www.example.com/second.html
If I type just: www.example.com/second it is not possible to open the page.
Can you maybe tell me what I do wrong?
You need to edit your htaccess, try this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

codeigniter page not found on live server

codeigniter page not found showing but working fine in local server.
I had uploaded codeigniter file of one basic simple page on live server but there it is showing no page found and same file it is working on local server.
In that I had
mine.php ---- controller
index.php --- view
I loaded in routes default controller - mine in config base url- domain.com removed index.php also
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
can I know please why it is showing page not found, might be some routing issue but I had loaded default controller also. Please help out on this
First of all start error logging properly so you can see the actuall error.
Change your file name's first letter capital. This is mendetory as explained here ci3 manual - controllers. It says class name as well as file name must start with capital. ( If your Dev machine is windows then it will not show errors if you don't follow this rule. Because window's file system is case insensitive. But on your server it is linux.so it will show error)
If you still don't get it working then try access the url with index.php in it. Temporaryly disable .htaccess .If you get it working then may be you have problem in . htaccess. Try the following link to properly remove index.php from your url. Expression engine forum .This htaccess worked for me on all different server I have used.
add this in .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !^(index\.php|images|asset|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

CodeIgniter CSS .htaccess 404 error

I am building an admin section in codeigniter for my site and wanted to have a separate CSS folder for the CSS files for the admin section as they are going differ to those for the main site.
Current my CSS files sit in assets/css
I added and extra folder to that called admin and placed my new CSS files in that ie
assets/css/admin/css/style.css
However when I click the link in source code view to that stylesheet, I get a 404.
My current .htaccess reads as follows:
RewriteEngine On
RewriteCond $1 !^(index\.php|assets|editor|css\/|admin|js|scripts|images|img|media|xml|user_guide|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
What would I need to do to enable this file.
Note the strange thing is I have 4 CSS files in the folder, two of them whem clicked in the view source ope okay, and 2 of them contain the 404.
use this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

How can i route to a controller and function in codeigniter?

I need to route for example to "www.url.com/controller/function" i put the code in 'config.php' in routes but, doesn't work. i need to load to views in the same controller, without put 'index.php' in the url. It is possible?
By default, the index.php file will be included in your URLs:
www.url.com/index.php/controller/function
You can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the "negative" method in which everything is redirected except the specified items:
RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]
Put the .htaccess file containing the above code to your app root folder.
here is the helping url to remove the index.php from url
User Guide remove index.php
you have to use .htaccess file to remove index.php from url
Hope it helps
Updated
Have a look in the application\config\config.php file, there is a variable named 'index_page'
It should look like this
$config['index_page'] = "index.php";
change it to
$config['index_page'] = "";
here is the .htaccess file you can use this..
RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Here are some use full links.. you can follow these..
remove index.php stackoverflow
remove index.php codeigniter forum
Enable mod rewrite from your server
Hope these will help you

Codeigniter - no input file specified

I am a beginner in Codeigniter and I saw a CI tutorial and was just trying to do a simple thing. I downloaded the CI and added this file to controller directory, but it won't work.
<?php
class site extends CI_Controller
{
public function index()
{
echo "Hello World";
}
function dosomething()
{
echo "Do Something";
}
}
?>
When I try to access it using http://..../index.php/site I get the output ... "no input file specified" .... by the way, I named the file site.php
Just add the ? sign after index.php in the .htaccess file :
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
and it would work !
Godaddy hosting it seems fixed on .htaccess, myself it is working
RewriteRule ^(.*)$ index.php/$1 [L]
to
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
I found the answer to this question here..... The problem was hosting server... I thank all who tried .... Hope this will help others
Godaddy Installation Tips
RewriteEngine, DirectoryIndex in .htaccess file of CodeIgniter apps
I just changed the .htaccess file contents and as shown in the following links answer. And tried refreshing the page (which didn't work, and couldn't find the request to my controller) it worked.
Then just because of my doubt I undone the changes I did to my .htaccess inside my public_html folder back to original .htaccess content. So it's now as follows (which is originally it was):
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]
And now also it works.
Hint: Seems like before the Rewrite Rules haven't been clearly setup within the Server context.
My file structure is as follows:
/
|- gheapp
| |- application
| L- system
|
|- public_html
| |- .htaccess
| L- index.php
And in the index.php I have set up the following paths to the system and the application:
$system_path = '../gheapp/system';
$application_folder = '../gheapp/application';
Note: by doing so, our application source code becomes hidden to the public at first.
Please, if you guys find anything wrong with my answer, comment and re-correct me!
Hope beginners would find this answer helpful.
Thanks!
My site is hosted on MochaHost, i had a tough time to setup the .htaccess file so that i can remove the index.php from my urls. However, after some googling, i combined the answer on this thread and other answers. My final working .htaccess file has the following contents:
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
# If your website begins from a folder e.g localhost/my_project then
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase /
# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)
# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|app_upload|assets|css|js|images)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php?/$1 [PT,L]
</IfModule>
One of my Codeigniter apps started returning this error after i restarted my server.
When I checked the Codeigniter error log it says something like:
"...[error] 879#0: *273 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: open_basedir restriction in effect. File(/pathToWebsiteRootFolder/index.php) is not within the allowed path(s): ".
So I added this:
open_basedir= /pathToWebsiteRootFolder/index.php:
To a user.ini file I created in my website root folder.
And this Solved it.
FYI: Im using an NGINX web server.
However, Its strange because I didn't have to do this for the other Apps on the same server.

Resources