Welcome Guest, Not a member yet? Register   Sign In
Default routing setup
#1

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.
Reply
#2

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
Reply
#3

(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
Reply
#4

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
Reply
#5

@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?
Reply
#6

I have been RTFM about removing index.php from the URL https://www.codeigniter.com/user_guide/g.../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.
Reply
#7

(This post was last modified: 02-22-2019, 04:18 AM by InsiteFX. Edit Reason: added example )

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#8

(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
Reply
#9

(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.
Reply
#10

(This post was last modified: 05-22-2019, 11:00 AM by MAILITY.)

(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 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB