简体   繁体   中英

codeigniter site_url 404 page not found

I'm using CodeIgniter in localhost (MAMP) starting with the project example given with CodeIgniter itself. I want to load a view from welcome_message.php, so first of all in welcome Controller I've written

public function index()
{
    $this->load->helper('url');

    $this->load->view('welcome_message');
}

then I've create the new view with a simple text. In welcome_message.php I've put

<a href="<?php echo site_url('test');?>">Test</a>

(both the views are in views folder)

When I open welcome_message.php in my browser I see the link but when I click on it Test.php is not loaded. I read only

404 Page Not Found The page you requested was not found.

In other project that I've seen on the web this works without problems, I don't know how can I fix it.

I would recommend to check your .htaccess file. Create a new .htaccess file in the root of Code Igniter with the following:

RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]

Besides that your routing has to be done in

application/config/routes.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM