0

Similar question asked here: Htaccess rule to make urls like this ?page=1 look like /page/1 in Codeigniter

But I can't get the answer right.

My routes.php

$route[$key] = "home_controller/index";
$route['page/(:num)'] = 'home_controller/index/$1';

My .htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

My config.php

$root .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;
$config['index_page'] = '';
$config['uri_protocol'] = 'PATH_INFO';

Can't understand the syntax. Been looking all over in Codeigniter Docs such as; https://codeigniter.com/userguide3/general/routing.html I just can't seem to find the solution for this.

host/page/1

Is working but not redirecting to the desired page in other words its not corresponding to it's page in the pagination

host/?page=1

Is working but I simply want to get rid of ?page=

I also need to fix a path url for host/category/?page=1 to host/category/page/1

totoprayogo1916
  • 160
  • 4
  • 20

1 Answers1

0

I check your code, As I notice your routing was fine. But your mistake in the config.php file. Please, replace your code from

$root .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', 
$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;
$config['index_page'] = '';
$config['uri_protocol'] = 'PATH_INFO';

to

if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
 $uri = 'https://';
} else {
 $uri = 'http://';
}
$uri .= $_SERVER['HTTP_HOST'];
$config['base_url'] = $uri;
$config['base_url'] .= 
preg_replace('@/+$@','',dirname($_SERVER['SCRIPT_NAME'])).'/';


$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';