CodeIgniter beginner here. The base URL of my website is 'http://localhost/routing/'.
// config.php
$config['base_url'] = 'http://localhost/routing/';
I'm simply trying to route the url 'http://localhost/routing/admin' to the admin controller using the following rules but it doesn't work. Instead I have to use 'http://localhost/routing/index.php/admin'.
$route['default_controller'] = 'seasons';
$route['admin'] = 'admin';
$route['404_override'] = '';
Question: is there a way to remove 'index.php' from the url?
Make changes in .htaccess file and config.php
application/config.php
$config['index_page'] = '';
.htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
is there a way to remove 'index.php' from the url?
Yes, as well as being a very popular question on SO, it is covered in the CodeIgniter documentation (which is very good and I highly recommend reading).
In your .htaccess write this. Also look for additional information : Codeigniter Guide
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt) # exceptions
RewriteRule ^(.*)$ /index.php/$1 [L]
Related
H,
I'm using codeigniter hmvc framework.i don't know how to configure this fo subdomain. i've installed it but not working. any help please.
project/
application/
controller/installer
modules/
default controller is pointed to installer.php
$route[default_controller] = 'installer';
but unable access the controller.
No matter it is hosted in subdomain or main domain. You need to do couple of things to make it workable.
Step one
Config base_url in config.php as follows:
$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$config['base_url'] .= "://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
Step two Check your .htaccess. It should looks like as bellows:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Note: .htaccess vary depending on server. In some server (e.g.: Godaddy) need to use the following .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Hope it will help you.
find this file
application/config/config.php
edit here thats all
$config['base_url'] = "http://subdomain.example.com/";
I am using the Pagination library in Codeigniter, and the links it creates are exactly what I'm looking for. When I click on the link to go to the next page I get a 404.
My base url (index page) is: http://localhost/foo
My routing is:
$route['default_controller'] = 'main';
$route['page/(:num)'] = 'main/page/$1';
I want to be able to go to the url: http://localhost/foo/page/2 to get the second page. main is the controller. page is a function inside main.
I can type in the url http://localhost/foo/index.php/main/page/2 and get to the correct page, but I do not want to have the index.php/main in the url.
What am I doing wrong?
You aren't doing anything wrong. If you want to remove the index.php from the url:
Leave in blank $config['index_page'] attibute on the application/config/config.php file and make sure that you have a .htaccess that contains
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Also make sure the apache server has mod_rewrite enabled and in the configuration of apache AllowOverride attribute it's been set to All
In you Controller(In pagination code) $config['base_url'] should be
$config['base_url'] = base_url() . 'foo/page/';
In routes.php
$route['page/(:num)'] = 'main/page/$1';
$route['page'] = 'main/page';//add this line
In .htaccess,(Place outside application folder)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Note: To use base_url() in config/autoload.php
$autoload['helper'] = array('url');//url
and in config/config.php, (Change this)
$config['base_url'] = '';
$config['index_page'] = '';
I am new in codeigniter and I love to use it in my future projects too.
I having a big time problem to make my url user friendly.
I have a website running that has a lot of pages, so URLs get too big and they look too bad.
So what I want to do, is shorten my URLs. For example:
www.abc.com/index.php/main/home
I want to make something like this:
www.abc.com/home
So my question is, How should I do this thing in CodeIgniter 2.2.3 ? Is there any demo?
I was see so many links for it but it can not full fill my requirement so please help me..
You can use routes for this purpose
To remove index.php use .htaccess with following code
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
and in config.php
$config['uri_protocol'] = 'AUTO';
now in your routes application/config/routes.php
$route['home']='main/home';
To remove index.php, place .htaccess outside application folder (root)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
To short URL, use config/routes.php
$route['home'] = "main/home";
Ex:
To use this I'm Moving
Firstly i create .htaccess file and put this code in it..
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /xyz.co/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
than go to application/config/routes.php and put below code.
$default_controller = "auth";
$controller_exceptions = array('main');
$route['default_controller'] = $default_controller;
$route["^((?!\b".implode('\b|\b', $controller_exceptions)."\b).*)$"] = $default_controller.'/$1';
$route['404_override'] = 'error';
$route['translate_uri_dashes'] = FALSE;
and in config.php
$config['uri_protocol'] = 'AUTO';
thats all...
I created a project using CI(version 3.0.0), and it works perfectly in XAMPP localhost. And i upload that project to sub domain then its giving an error Click here.
I Handle Router's and config setting as well. So what is this error?? how to avoid this?? There are some answers, But not suit for this.
Config.php
$config['base_url'] = '';
$config['index_page'] = '';
Routes.php
$route['default_controller'] = 'shop';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
.htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Change the name of your controller, model, and other your class to Capitalize.
Example :
your own controller test.php change to Test.php
It should be work.
Its because your server is Linux, and Linux is case sensitive.
There are many tutorials that talk about deleting index.php from the url. But I want one step forward of it.
The link is: www.example.com/index.php/controller/function/single-variable
I want it like: www.example.com/some-name-that-i-put/single-variable
I cannot find a tutorial to do such a thing. How to do it?
i wasnt sure whether you were wanting to do direct URL rewrites how CI does it out of the box or not... but this is how you do URL Rewrites:
your class/function/id example.com/news/article/13 transposes to: example.com/class/function/ID
http://codeigniter.com/user_guide/general/urls.html
you can set this by doing two things:
in your config.php file under application/config/ edit these:
approx line 80: $config['uri_protocol'] = 'REQUEST_URI'; // i set this to request_URI as it always works for me..
approx line 93: $config['url_suffix'] = '.html'; // this is optional, if you want /13.html
approx line 62: $config['index_page'] = ''; //set this to blank
create a .htaccess in http root:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
This is how you do URI Route changes
if you want to change the organization of the URI you can use URI Routes defined in routes.php as described here: http://codeigniter.com/user_guide/general/routing.html
Check out this CodeIgniter user guide.
Try this codeigniter user guide
https://www.codeigniter.com/user_guide/general/routing.html
Try this
in your config file place these
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';
$config['index_page'] = '';
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = FALSE;
after this make a .htaccess file at your root directory and put this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
this will Definitely help you