我想从我的网址
中删除“index.php”http://localhost/simpleblog/index.php/blogger/NewBlogs
我需要它
http://localhost/simpleblog/blogger/NewBlogs
这里显示我的控制器代码
class Blogger extends CI_Controller {
public function NewBlogs()
{
$this->load->helper('url');
$this->layout="Yes"; //<-- add this*/
/* $this->load->view('welcome_message');*/
$this->load->view('Pages/SecondPage');
}
}
默认控制器
public function index()
{
$this->load->helper('url');
$this->layout="Yes"; //<-- add this*/
/* $this->load->view('welcome_message');*/
$this->load->view('Pages/MainPage');
}
如何删除index.php?
答案 0 :(得分:1)
默认情况下,index.php
文件将包含在您的网址中:
example.com/index.php/news/article/my_article
您可以使用带有一些简单规则的.htaccess
文件轻松删除此文件。
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
答案 1 :(得分:0)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
答案 2 :(得分:0)
您应该在.htaccess文件中输入此代码
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
和 在config.php文件中替换此代码
$config['index_page'] = 'index.php';
To
$config['index_page'] = '';
答案 3 :(得分:0)
删除index.php文件
$config['index_page'] = 'index.php';
替换为
$config['index_page'] = '';
即/.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
使用名称.htaccess