1

基本上,我有一个表格类别,例如

|id|name    |
|1 |home    |
|2 |tutorial|
...

和表帖之类的

|id|name           |cateID|
...
|5 |getting started|2
...

1.如果我tutorial在类别中查看(点击),那么 url 会像

`index.php/nameOfControllerFile/functionName/2`

2是表类别的 id。

但我看到我查看的所有网站。看起来像

category/tutorials.htm or like category/tutorials/

2.如果我查看getting started帖子,那么 url 会像

index.php/nameOfControllerFile/functionName/5

5是表格帖子的 ID。

但我看到我查看的所有网站。看起来像

category/tutorials/getting-started.htm

这是网站之类的结构http://line25.com/category/tutorials

我怎样才能将基本网址更改为上面的网址?

编辑

如果有两个帖子的标题相同,会发生什么

|id|name           |cateID|
...
|5 |getting started|2
|8 |getting started|2 
...
4

4 回答 4

0

不知道你在问什么。可能是路线。核实:

假设您有一个名为tutorials. 在该控制器中,您具有view查看特定教程的index功能,以及教程主页的功能,您可以在其中查看所有教程,如您显示的 line25 链接中所示。

注意:请参阅https://stackoverflow.com/a/9667306/183254https://www.google.com/search?q=site%3Astackoverflow.com+codeigniter+remove+index.php,此问题中的其他答案等来了解如何从 url 中删除 index.php。这个答案的其余部分将假设您已经弄清楚了那部分(url 中没有 index.php)。

所以:

class Tutorials extends CI_Controller{

    function index(){
        //view all tutorials
    }

    function view($tutorial_identifier){
        //view single tutorial based on $tutorial_identifier
        //which can be either an id or a name
    }
}

会让你喜欢的网址

http://www.example.com/tutorials/view/5 

查看单个教程,以及

http://www.example.com/tutorials/

查看所有教程。

重要阅读:路线

如果您希望网址看起来更像

http://www.example.com/tutorials/5 

对于教程#5,您可以使用类似的路线

$route['tutorials/(:num)'] = "tutorials/view/$1"; 

如果你想让它看起来更像

http://example.com/tutorials/getting-started

您可以添加一条路线,例如

$route['tutorials/(:any)'] = "tutorials/view/$1";

并更改view控制器功能中的逻辑,以通过name而不是id.

于 2013-09-06T18:56:31.993 回答
0

.HTACCESS 将帮助您重写 URL 但您必须根据您的 .HTACCESS 文件更改配置中的路由文件。

于 2013-09-06T18:10:10.363 回答
0

请参阅此处找到的 Codeigniter 帮助文档:

http://ellislab.com/codeigniter/user-guide/general/urls.html

请参阅名为删除 index.php 文件的部分

于 2013-09-06T17:24:39.503 回答
0

它是通过.htaccessapache 服务器中的文件完成的,重写 url ( mod rewrite ),例如:

RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php

当您提供带有 的 url 时,上面的行将查找带有.php扩展名的文件.html,这意味着,如果您home.html在地址栏中写入,则服务器将查找该home.php文件并启动它。检查这个这个

另外,对于CodeIgniter,您可以检查此答案

于 2013-09-06T17:27:32.217 回答