【发布时间】:2018-12-10 15:21:13
【问题描述】:
有很多教程都在讨论从 url 中删除 index.php。但我想更进一步。
链接是:www.example.com/index.php/controller/function/single-variable 我希望它像:www.example.com/some-name-that-i-put/single-variable
我找不到做这种事情的教程。怎么做?
【问题讨论】:
有很多教程都在讨论从 url 中删除 index.php。但我想更进一步。
链接是:www.example.com/index.php/controller/function/single-variable 我希望它像:www.example.com/some-name-that-i-put/single-variable
我找不到做这种事情的教程。怎么做?
【问题讨论】:
我不确定您是否想要直接进行 URL 重写,CI 是如何开箱即用的......但这就是您执行 URL 重写的方式:
你的类/函数/id example.com/news/article/13 转换为:example.com/class/function/ID
http://codeigniter.com/user_guide/general/urls.html
你可以通过做两件事来设置它: 在 application/config/ 下的 config.php 文件中编辑这些:
approx line 80: $config['uri_protocol'] = 'REQUEST_URI'; // i set this to request_URI as it always works for me..
approx line 93: $config['url_suffix'] = '.html'; // this is optional, if you want /13.html
approx line 62: $config['index_page'] = ''; //set this to blank
在 http 根目录中创建一个 .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
这就是更改 URI 路由的方式
如果你想改变 URI 的组织,你可以使用在 routes.php 中定义的 URI 路由,如下所述:http://codeigniter.com/user_guide/general/routing.html
【讨论】:
【讨论】:
试试这个 codeigniter 用户指南 https://www.codeigniter.com/user_guide/general/routing.html
【讨论】:
试试这个 在你的配置文件中放置这些
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';
$config['index_page'] = '';
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = FALSE;
之后在你的根目录下创建一个 .htaccess 文件并将其放入
重写引擎开启
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
重写规则 ^(.*)$ index.php/$1 [L]
这绝对会帮助你
【讨论】: