我的网址是:
example.com/controller/function/parameter
=> example.com/category/index/category_name
我需要:
example.com/category/category_name
我已经尝试过*提供的几种解决方案,但是对此却无法解决.它要么重定向到主页,要么找不到404页面.
我尝试过的选项是:
$route['category'] = "category/index"; //1
$route['category/(:any)'] = "category/index"; //2
$route['category/(:any)'] = "category/index/$1"; //3
另一条路线是:
$route['default_controller'] = 'home';
htaccess文件:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$index.php/$1 [L]
在配置文件中,我有:
$config['url_suffix'] = '';
解决方法:
我认为您的.htaccess文件中有错误.请在下面找到.htaccess文件的代码.
您可以使用RewriteBase为您的重写提供基础.
RewriteEngine On
RewriteBase /campnew/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$index.php/$1 [L]
在Controller中,您的方法.
public function index($category_name = null) {
$this->load->model('category_model');
$data = array();
if ($query = $this->category_model->get_records_view($category_name)) {
$data['recordss'] = $query;
}
if ($query2 = $this->category_model->get_records_view2($category_name))
{
$data['recordsc2'] = $query2;
}
$data['main_content'] = 'category';
$this->load->view('includes/template', $data);
}
在模型文件中
public function get_records_view($category){
$this->db->where('a.linkname', $category);
}
让我知道是否有效.