【问题标题】:URL Change in Codeigniter frameworkCodeigniter 框架中的 URL 更改
【发布时间】:2018-04-17 12:38:57
【问题描述】:

我有一个网址

http://localhost/himalaya/webmanager/recentUpdate/index/edit-recent-update-1

但我希望它使 URL 像这样:

http://localhost/himalaya/webmanager/recentUpdate/edit-recent-update-1.

控制器名称为recentUpdate,方法名称为index。我的问题是如何从 codeigniter 框架中的 URL 中删除 index 方法名称?

【问题讨论】:

  • 我已按照您的说明进行操作,但索引方法并未隐藏在 url 中
  • 您也可以为此使用路由。参见 CI 路由
  • 我用过这个路由 $route['webmanager/recentUpdate/index/(:any)'] = 'webmanager/recentUpdate/$1';但不隐藏索引方法名称
  • 因为您正在显示此 CI $route['new route'] = old route
  • 所以我必须为路由控制器名称recentUpdate和参数写什么是通过索引方法。

标签: codeigniter


【解决方案1】:

您好,首先您只需阅读 codeigniter 中的 index.php 是什么。 https://ellislab.com/codeigniter/user-guide/general/urls.html

要删除索引,请在 .htaccess 文件中编写路由规则。 应用文件夹上方

重写引擎开启

RewriteBase /project_name/

重写规则 ^(.*)$ index.php?/$1 [L]

【讨论】:

    【解决方案2】:

    在您的项目中添加 .htaccess 文件。

    在其中添加代码。

    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-02
      • 2021-11-23
      • 1970-01-01
      • 2011-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多