Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeigniter url routing selecting menu item adds segments to url
    text
    copied!<p>In a fresh installation of codeigniter 2.1.3 I have a controller 'home.php' with two functions:</p> <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Home extends CI_Controller { public function index() { $this-&gt;load-&gt;view('home'); } public function homefunction() { $this-&gt;load-&gt;view('homefunction'); } } </code></pre> <p>I have a view 'home.php'. The anchors represent the menu:</p> <pre><code>&lt;p&gt;Home&lt;/p&gt; &lt;br/&gt; &lt;a href="home"&gt;Home&lt;/a&gt; &lt;a href="home/homefunction"&gt;Home Function&lt;/a&gt; </code></pre> <p>and a view 'homefunction.php'</p> <pre><code>&lt;p&gt;Function in the Home controller&lt;/p&gt; &lt;br/&gt; &lt;a href="home"&gt;Home&lt;/a&gt; &lt;a href="home/homefunction"&gt;Home Function&lt;/a&gt; </code></pre> <p>my routes:</p> <pre><code>$route['default_controller'] = "home"; </code></pre> <p>I have 'eliminated' index.php from the URL with .htaccess and config.php my .htaccess is:</p> <pre><code>RewriteEngine On RewriteBase /test/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [PT,L] </code></pre> <p>in the config.php file I have set:</p> <pre><code>$config['base_url'] = 'http://localhost/test'; $config['index_page'] = ''; </code></pre> <p>Now I run <code>http://localhost/test</code> and my home page loads with the menu. The url in the browser is <code>localhost/test/</code>. Then I click the 'Home' anchor menu item the url in the browser becomes <code>localhost/test/home</code>. I click the other menu item 'Home Function' the home function page loads and the url becomes <code>localhost/test/home/homefunction</code>. In the menu of the home function view I click the 'home' item and the url becomes <code>localhost/test/home/home</code>. <strong>I was expecting to become</strong> <code>localhost/test/home</code>. Then I click the menu item 'Home Function' the home function view is not loading and the url becomes <code>localhost/test/home/home/homefunction</code>, the homefunction page is <strong>not</strong> loading I click again home and I get in the url <code>localhost/test/home/home/home</code> and this goes on each time I click home function menu item and then home menu item a home section is added in the url.</p> <p>I know it is something simple that maybe has to do with routing but I' stuck and I can't find a similar problem with google. Can anyone help?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload