I tried to encode the ID of a journal in the URL of my Code Igniter application and the retrieve it in my controller. My end goal is to access the page http://mysite.com/journal/3 and get to access a page containing details about the journal with ID 3.
In my journal.php controller file, I have
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Journal extends Controller {
public function index($journalId) {
$data['journalId'] = $journalId;
$this->view->load('journalPage', $data);
}
}
?>
In my journalPage.php view file, I have
This event has ID <?= $journalId ?>.
I wrote this rule in my routes.php file.
$route['journal/(:num)'] = 'journal/$1';
Here is the .htaccess file in my html public folder.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [QSA,L]
</IfModule>
However, when I go to mysite.com/journal/3, I get a 404 error. Why?
mysite.com/index.php/journal/3mysite.com/journal/3normysite.com/index.php/journal/3are working. Interestingly, going tomysite.com/journal/works. However, the text displayed isThis event has ID .without an actual event ID..htaccessandconfig/routes.phpmight help us make a better guess.