以下是CI Url重寫的示例
首先.htaccess擺脫索引。 PHP
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
然後在config.php編輯
$config['index_page'] = '';
然後控制器和routes.php文件只是簡單的例子,在config文件夾
$route['default_controller'] = "main";
$route['404_override'] = '';
$route["contact"] = 'main/contact';
$route["(.*)"] = 'main/tekstovi/$1';
而且例如控制器
class Main extends CI_Controller {
public function index()
{
$this->home();
}
public function home()
{
$this->load->view("view_home", $data);
}
public function tekstovi()
{
$data['results'] = $this->get_db->('TABELNAME',$this->uri->segment(1));
$this->load->view("view_tekstovi", $data);
}
public function contact()
{
$this->load->view("view_contact", $data);
}
}
您可以添加.html在URL的末尾只需要編輯config.php文件
$config['url_suffix'] = '.html';
這僅僅是簡單的例子,嘗試添加自己的:)
在routes.php文件文件中添加以下內容: $路線['用戶/(:任何)'] ='user/getProfile/$ 1'; – Ula
我同意Ula,routes.php應該被用來處理CI中的路由請求,而不是.htaccess文件。 – Ohgodwhy