CodeIgniter Forums
Default routing setup - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: Installation & Setup (https://forum.codeigniter.com/forum-9.html)
+--- Thread: Default routing setup (/thread-72566.html)

Pages: 1 2


Default routing setup - Tiny - 01-06-2019

I installed Codeigniter for the first time, read documentation.
According to docs, the URI consists of set of segments:
PHP Code:
http://example.com/index.php/[controller-class]/[controller-method]/[arguments] 
But that scheme doesn't work for me out of the box. I've created blank controller application/controllers/Blog.php, and tested url 
PHP Code:
http://example.com/index.php/blog 
The result was Error 404.
Here is the code of the controller:
PHP Code:
<?php
class Blog extends CI_Controller {

 
       public function index()
 
       {
 
               echo 'Hello World!';
 
       }

base_url at application/config/config.php is set correctly to the server name.
So the problem is, that default controller at
PHP Code:
http://example.com/
and
http://example.com/index.php 

works, but everything else doesn't respond.


RE: Default routing setup - jaweb - 01-07-2019

Hi, does http://example.com/index.php/blog/index work?
If that works you have to edit your routes.php (in map application/config)

grtz Jaweb


RE: Default routing setup - Tiny - 01-07-2019

(01-07-2019, 02:08 AM)jaweb Wrote: Hi, does http://example.com/index.php/blog/index work?
If that works you have to edit your routes.php (in map application/config)

grtz Jaweb

Thank you for reply. Neither URL http://example.com/index.php/blog/index, nor http://example.com/index.php/welcome (default controller)  work properly.
Even http://example.com/index.php/ produces Error 404.
But 'default_controller' option works well. It always call correct controller on http://example.com/index.php


RE: Default routing setup - jaweb - 01-07-2019

Hi Tiny,

Make sure your 'base_url' is set in the config/config.php.
Then set a route in your routes.php like: $route['blog/index'] = 'blog/index';  put it above the other entries.
When you enter the url leave 'index.php' out.

So the link will be "....example.com/blog/index"

Hope that wil work. Smile

Grtz Jaweb


RE: Default routing setup - php_rocs - 01-07-2019

@Tiny,

What web server are you using? If you are using Apache do you have the mod_rewrite plugin turned on and the .htaccess file in root CI directory?


RE: Default routing setup - Les Kaye - 02-21-2019

I have been RTFM about removing index.php from the URL https://www.codeigniter.com/user_guide/general/urls.html
The instructions include putting this line in .htaccess
RewriteRule ^(.*)$ index.php/$1 [L]
This did not work for me until I put a slash in front of index.php like this
RewriteRule ^(.*)$ /index.php/$1 [L]
Is the manual wrong or is this an alternate configuration? I am using a Linux server with index.php in public_html. I suggest the manual needs updating as people will waste time over this.


RE: Default routing setup - InsiteFX - 02-22-2019

There should be a trailing slash / on the end of the base url in config.php

Route:
PHP Code:
/**
 * controller/method/parameters
 *    blog    index     pram
 */
$route['blog/index/(.+)'] = 'blog/index/$1'

Something like.


RE: Default routing setup - Soon - 04-13-2019

(02-21-2019, 12:55 AM)Les Kaye Wrote: I have been RTFM about removing index.php from the URL
The instructions include putting this line in .htaccess
RewriteRule ^(.*)$ index.php/$1 [L]
This did not work for me until I put a slash in front of index.php like this
RewriteRule ^(.*)$ /index.php/$1 [L]
Is the manual wrong or is this an alternate configuration? I am using a Linux server with index.php in public_html. I suggest the manual needs updating as people will waste time over this.

Thanks for the share Smile


RE: Default routing setup - MAILITY - 05-21-2019

(01-07-2019, 01:07 PM)jaweb Wrote: Hi Tiny,

Make sure your 'base_url' is set in the config/config.php.
Then set a route in your routes.php like: $route['blog/index'] = 'blog/index';  put it above the other entries.
When you enter the url leave 'index.php' out.

So the link will be "....example.com/blog/index"

Hope that wil work. Smile

Grtz Jaweb
I installed Codeigniter for the first time, read documentation.


RE: Default routing setup - MAILITY - 05-21-2019

(01-07-2019, 03:15 AM)Tiny Wrote:
(01-07-2019, 02:08 AM)jaweb Wrote: Hi, 
If that works you have to   Xender  Discord  Omegle edit your routes.php (in map application/config)

grtz Jaweb

Thank you for reply. Neither URL, nor  /welcome (default controller)  work properly.
Even  Error 404.
But 'default_controller' option works well. It always call   correct controller on