Default URL is not working in Codeigniter - codeigniter

I am new in Codeigniter framework. I am using HMVC design pattern
I have a issue with base url when I enter URL like this https://sitename/ its show blankpage and
when enter URL like this https://sitename/controller then show it main page of website
Config.php
$config['base_url'] = 'https://sitename/';
Routes.php
$route['default_controller'] = 'home';
$route['404_override'] = 'notify/show_404';
$route['translate_uri_dashes'] = FALSE;
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
ErrorDocument 404 index.php
Options -Indexes
How to show main page of website on this URL https://sitename/

Related

CodeignIter with HTTPS page not rendering domain/H.html not working(404 Error)

Website is normally working without HTTPS.
with HTTPS only homepage is working but other pages like (https://domain.in/contact.html) not working(404 Error Page)
My Files.
application/config/config.php
$config['base_url'] = '';
$config['index_page'] = '';
.httaccess file is
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Please suggest me what to do.
Thanks in Advance.

Codeigniter routing using base_url

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'] = '';

How should I minimize url in CodeIgniter 2.2.3

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...

Nginx rewrite rules for codeigniter

Earlier my web server worked on Apache, now only at Nginx.
I tried rewrite all rules for this example:
http://www.farinspace.com/codeigniter-nginx-rewrite-rules/
But still all URL same as:
mysite.com/stocks
dont work.
Where stocks - is name of controller Codeigniter.
In .htaccess file were the next rules:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
And config.php had the following content:
$config['index_page'] = '';
$config['uri_protocol'] = "REQUEST_URI";

CodeIgniter routing always through index.php?

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]

Resources