所有URL自动为CodeIgniter URL后缀.html

JEW*_*MED 2 php .htaccess codeigniter

我是CodeIgniter的新手.我在我的localhost中设置了CI.本地主机/ MyProjects下/笨/首页/指数

我可以从url中删除index.php并且我也完成了.html后缀所以,我可以访问localhost/MyProjects/CodeIgniter/welcome/index.html并且它正常工作.

所以我使用的是这样的标签:

<a href="<?php echo base_url(); ?>welcome/register.html">Register</a>
Run Code Online (Sandbox Code Playgroud)

但是,我不想手动使用链接中的.html.

有任何解决方案,以自动显示我的访客.html后缀Eg.localhost/MyProjects/CodeIgniter/welcome/index.html或localhost/MyProjects/CodeIgniter/welcome/about.html等

这是我的htaccess http://pastebin.com/cXUFjvbp

Man*_*ngh 5

更改您的 config.php 文件

$config['url_suffix'] = '.html';
Run Code Online (Sandbox Code Playgroud)


Wah*_*nto 5

只需url_suffixconfig.php中编辑.....

$config['url_suffix'] = '.html';
Run Code Online (Sandbox Code Playgroud)

使用 site_url()

<!-- No need .html -->
<a href="<?php echo site_url('welcome/register'); ?>">Register</a>
<!-- <a href="http://domain/welcome/register.html">Register</a> -->
Run Code Online (Sandbox Code Playgroud)

要么 anchor()

// No need .html
echo anchor('welcome/register', 'Register');
// <a href="http://domain/welcome/register.html">Register</a>
Run Code Online (Sandbox Code Playgroud)

注意:不要忘了加载网址助手$this->load->helper('url');.