Page route CodeIgniter I - codeigniter

I am using a reference book called PHP and MVC with CodeIgniter, and I’m following the examples of projects putting in my personal pc.It runs fine at my local PC and but gives some error at webserver. Diagnosis: The problem in question is the routes of pages. in my personal pc works normally, but when I put it on the web server can not find the requested page.
http://orion.locadados.com.br/~wladi/Carrinho_Compras/
http://orion.locadados.com.br/~wladi/Carrinho_Compras/categoria/artigos-esportivos
The routes defined in my project are as default for any server, because they are in the project folder itself. Just do not put the line of code, it would not know which part of the code put online.
How can i fix this?
file .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
the file routes.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| URI ROUTING
| -------------------------------------------------------------------------
| This file lets you re-map URI requests to specific controller functions.
|
| Typically there is a one-to-one relationship between a URL string
| and its corresponding controller class/method. The segments in a
| URL normally follow this pattern:
|
| example.com/class/method/id/
|
| In some instances, however, you may want to remap this relationship
| so that a different class/function is called than the one
| corresponding to the URL.
|
| Please see the user guide for complete details:
|
| http://codeigniter.com/user_guide/general/routing.html
|
| -------------------------------------------------------------------------
| RESERVED ROUTES
| -------------------------------------------------------------------------
|
| There area two reserved routes:
|
| $route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
|
| $route['404_override'] = 'errors/page_missing';
|
| This route will tell the Router what URI segments to use if those provided
| in the URL cannot be matched to a valid route.
|
*/
$route['default_controller'] = "home";
$route['categoria/(:any)'] = "home/categoria/$1";
$route['produto/(:any)'] = "produtos/detalhes_produto/$1";
$route['404_override'] = '';
/* End of file routes.php */
/* Location: ./application/config/routes.php */

try with this .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^sys.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^app.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
assuming that your system folder is sys and application folder is app

For me this htaccess works with the latest CI version
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]
Try with this

Related

Deploy Laravel project in server without changing the public folder path

I have found a solution for laravel Deployment
Most of us are stucked in the laravel deployment in server, most reason is changing the public path and modified the server.php
Please find the answer below:-
Just Change the .htaccess and the problem is solved:
Change Two files in root 1..htaccess, 2. .index.php
And Change Two files in public folder 1..htaccess, 2. .index.php
Root Folder
.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php
Root Folder
index.php
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylor#laravel.com>
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
/*if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}*/
require_once __DIR__.'/public/index.php';
Public Folder
.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Public Folder
index.php
<?php
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Check If The Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is in maintenance / demo mode via the "down" command
| we will load this file so that any pre-rendered content can be shown
| instead of starting the framework, which could cause an exception.
|
*/
if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {
require $maintenance;
}
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/
require __DIR__.'/../vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/
$app = require_once __DIR__.'/../bootstrap/app.php';
$kernel = $app->make(Kernel::class);
$response = $kernel->handle(
$request = Request::capture()
)->send();
$kernel->terminate($request, $response);
Find the solution and cheers...
Happy Coding..

CodeIgniter application links not working

I installed an application built with CodeIgniter on my local computer which has MAMP. The home page contains a bunch of links to other pages. Clicking any of the links doesn't do anything. The page just refreshes but the browser doesn't redirect. Looking at this piece of ducumentation, I think that the URI doesn't have any data and therefore it just goes back to the home page. What do I need to do to test this and fix it?
There are three reserved routes:
|
| $route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
change your .htaccess to Codeingiter's provide htaccess file below.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
place that to your root application folder.
Set the base_url of your application in config.php to the same url you are using to access the website, it should be something like this:
$config['base_url'] = "http://localhost/your_app_directory_name";
It should work.
For .htaccess use this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

How to remove index.php with Codeigniter in Godaddy.com

i built a website with codeigniter and when i uploaded it it give me that error The requested document was not found on this server. i know that the problem is with my .htaccess code. so anyone can help me?
RewriteEngine on
RewriteCond $1 !^(index\.php|css|js|robots\.txt|images|itempics)
RewriteRule ^(.*)$ /index.php/$1 [L]
Try this (anything listed in with the js|css etc will not use the rewrite
Options +FollowSymlinks
RewriteEngine on
# On Rackspace and getting 404's? Uncoment this by removing the # :
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_rewrite.c>
RewriteRule ^(.+)\.(\d+)\.(js|css|docs|img|invoices|support|demos|blog|devx)$ $1.$3 [L]
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
On one shared hosting I have this set:
RewriteEngine on
RewriteBase /
Options -Indexes
RewriteCond $1 !^(index\.php|robots\.txt|assets)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/\?$1 [L]
Also,
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
$config['base_url'] = 'http://example.tld/';
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';

codeigniter on xampp wants me to use index.php in uri

I have a problem with setting up a local testing environment using codeigniter and an already existing code.
Well, the problem is, that I can't open a page, without having "index.php" in my URL. So, "test.mydomain.local/index.php/search" works fine while "test.mydomain.local/search" does not. But all links in the code, excluding the action-URLs in form-tags, doesn't have this "index.php" in the URL.
How can I solve the problem, that codeigniter or the xampp need this "index.php" in the URL? Do I need to change something in my code or maybe in .htaccess?
Here is my config.php
$config['base_url'] = "http://test.mydomain.local/";
$config['index_page'] = "index.php";
$config['uri_protocol'] = "AUTO";
Well, this code forces the "index.php" in the action-URL in form tags. But actually I dont want to have this index.php in any URL. So that my config.php should look like this, I guess:
$config['base_url'] = "http://test.mydomain.local/";
$config['index_page'] = "";
$config['uri_protocol'] = "AUTO";
Here is the .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
### force www
RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule (.*) h t t p : / / w w w . m y d o m a i n . c o m/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^domain.local [NC]
RewriteRule (.*) h t t p : / / t e s t . d o m a i n . l o c a l/$1 [R=301,L]
### if the is not a request for an existing file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
### and the URI does not end with a /
RewriteCond %{REQUEST_URI} !^([^?]*)/($|\?)
### redirect and add the slash.
RewriteRule ^([^?]*) $1/ [L,R=301]
### if the is not a request for an existing file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# rewrite to index.php passing the URI as a path, QSA will preserve the existing query string
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Can anybody help me? It is driving me nuts!
I use xampp and have found this htaccess is best. Do not for get to put your base url in config/config.php and remove index.
.htaccess
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Your config.php
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| If this is not set then CodeIgniter will try guess the protocol, domain
| and path to your installation. However, you should always configure this
| explicitly and never rely on auto-guessing, especially in production
| environments.
|
*/
$config['base_url'] = 'http://localhost/project name/';
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';

CodeIgniter form_open not hitting controller

Hi all I am new to CodeIgniter framework. I tried to develop a page which contains a form.
Here is the view
<?php echo form_open('Site/check');?>
User Name: <?php echo form_input(array('id'=>'Username' ,'name'=>'username' ,'class="input-medium " ')); ?>
Add User:<?php echo form_submit('submit','Add User','class="btn btn-primary"');?>
<?php echo form_close();?>
This is the controller
<?php class Site extends CI_Controller{
function login() {
$data['records']="BHOOM!!!";
$this->load->view('login',$data);
}
function check() {
$this->load->view('showmessage');
}
}
?>
The showmessage is a PHP page with a hello in <h1> tags.
I already googled and searched for similar issues, but I didn't get any resolution
The base url is localhost/ci/index.php
Error
Unable to load the requested file: showmessage.php
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|js|css|img\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Here is a tutorial straight from EllisLab. Follow steps and you will get your form working.
The most common mistakes,
not loading form helper
htaccess. is set wrong, or paths are wrong (capital letters etc.).
config.php is not set properly
not passing data to view ($this->load->view('some_view', $data);
Hence you did not provide us error message if one exists there is no possible help from the community.
For more debug info please turn on codeigniters profiler ($this->output->enable_profiler(TRUE);), use PHPs native function var_dump($variable);.
Make sure error reporting is set to E_ALL in your index.php
edit
Make sure your /config/config.php
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = "";
make your .htaccess this file should be located in root of your project eg. /ci/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci/
# Reenable after getting ssl cert
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
# Removes access to the system folder by users
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
# When your application folder isn't in the system folder This snippet prevents user access to the application folder
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
# Checks to see if the user is attempting to access a valid file, such as an image or css document, if this isn't true it sends the request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's can be sent to index.php, and everything works as normal.
ErrorDocument 404 /index.php
</IfModule>
just use this type of code for your trial
view
<?php
echo form_open('controllet_name/method_name');
form_input(array('id'=>'Username' ,'name'=>'username' ,'class="input-medium " '));
form_close();
?>
controller
()
{
$name=$this->input->post('username');
echo $name ;
}
I think your RewriteRule is wrong.
Try:
RewriteRule ^(.*)$ /ci/index.php/$1 [L]

Resources