# CodeIgniter 添加 URL 后缀

**URL:** <https://www.isharkfly.com/t/codeigniter-url/2870>\
**Category:** PHP\
**Created:** [January 5, 2014, 12:35am UTC](https://www.isharkfly.com/t/codeigniter-url/2870 "2014-01-05T00:35:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [January 5, 2014, 12:35am UTC](https://www.isharkfly.com/t/codeigniter-url/2870/1 "2014-01-05T00:35:17Z")

</div>

通过设置 config/config.php 文件，你可以为 CodeIgniter 生成的 URL 添加一个指定的文件后缀。举例来说，如果 URL 是这样的：`example.com/index.php/products/view/shoes`你可以随意添加一个后缀，例如 .html，使其显示为：`example.com/index.php/products/view/shoes.html`(注：英文中由于参数可直接看懂其含义，并未说明应修改哪个参数，在这里应修改$config[‘url\_suffix’]这个参数。)

注意:如果你的项目不在根目录请把上面这一句改为：RewriteRule ^(.\*)$ index.php/$1 [L]

在上面的例子中，可以实现任何非 index.php、images 和 robots.txt 的 HTTP 请求都被指向 index.php。
