0

我想知道是否有任何方法可以使用 .htaccess 缩短 codeigniter 中的 url。例如,我有 example.com/user/account/settings,我想将 url 缩短为 example.com/settings。与我们从地址栏中删除 index.php 的方式相同,有没有办法从同一地址栏中删除更多项目?

4

2 回答 2

3

它是通过routes.phpCodeIgniter 应用程序文件夹中的文件完成的。文档

对于您的示例,这真的很简单,只需在文件中添加一行:

$route['settings'] = 'user/account/settings';
于 2012-07-08T12:44:39.020 回答
1

默认情况下,index.php 文件将包含在您的 URL 中:例如

example.com/index.php/news/article/my_article

您可以使用带有一些简单规则的 .htaccess 文件轻松删除此文件。以下是此类文件的示例,使用“否定”方法重定向除指定项目之外的所有内容:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

在上面的示例中,除 index.php、images 和 robots.txt 之外的任何 HTTP 请求都被视为对 index.php 文件的请求。

于 2012-07-08T12:46:52.520 回答