gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 02:43:47 25 4
gpt4 key购买 nike

我是 CodeIgniter 的新手。我在本地主机中设置了 CI,例如。 localhost/MyProjects/CodeIgniter/welcome/index

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

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

<a href="<?php echo base_url(); ?>welcome/register.html">Register</a>

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

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

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

最佳答案

只需编辑 config.php 中的 url_suffix .....

$config['url_suffix'] = '.html';

使用site_url()

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

anchor()

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

注意:不要忘记使用 $this->load->helper('url'); 加载 URL helper

关于php - CodeIgniter URL 后缀 .html 自动为所有 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23726776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com