【问题标题】:How can i fix routes of codeigniter 3?如何修复codeigniter 3的路线?
【发布时间】:2017-01-09 23:35:49
【问题描述】:

有些东西不工作,我的 routes.php 文件中有这个

$route['default_controller'] = 'books';
$route['404_override'] = '';
$route['translate_uri_dashes'] = TRUE;


$route['cities']['get'] = 'cities/index';
$route['cities/(:num)']['get'] = 'cities/find/$1';
$route['cities']['post'] = 'cities/index';
$route['cities/(:num)']['put'] = 'cities/index/$1';
$route['cities/(:num)']['delete'] = 'cities/index/$1';

和我的 .htaccess 像这样

Options FollowSymLinks
<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

这里的问题是,当我去 googleChrome 并输入这样的网址时: ....www.domain.com.mx/project-server/

它将我发送给默认控制器,它是书籍,欢迎,或任何地方。 但是当我想像这样在我的网址上输入它时

...www.domain.com.mx/project-server/books 出现这样的错误: 在此服务器上找不到请求的 URL /project-server/cities。

这是我在 github 上的项目 https://github.com/cmurra/project-server

【问题讨论】:

  • 错误 - 是 codeigniter 错误还是 apache 错误?
  • 好吧,我真的不舒尔,这就是我问XD的原因

标签: php .htaccess codeigniter routes codeigniter-3


【解决方案1】:

您可能还想检查配置 $route['translate_uri_dashes'] = TRUE; 尝试将其设置为 FALSE(您的 URL domain.com.mx/project-server/bookshttps://www.codeigniter.com/userguide3/general/routing.html

【讨论】:

  • 我已经做到了,但我没有我想要的路线:(它仍在使用 www.domain.com.mx/project-server/index.php/books。我希望有你说的路线 domain.com.mx/project-server/books
【解决方案2】:

将您的 htaccess 更改为此

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /<YOUR_ROOT_FOLDER>
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$l [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|images|robots\.txt|css)
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 / index.php
</IfModule>

编辑

澄清一下,我认为问题在于 codeigniter 正在寻找 index.php

www.domain.com.mx/project-server/index.php/books

www.domain.com.mx/index.php/project-server/books

就是其中之一

【讨论】:

  • 哇,它正在工作。谢谢。但在某些教程中,他们使用 www.domain.com.mx/project-server/books。就这样
  • 我可以打勾吗?不管怎样,你试过我的htaccess吗?我知道你在说什么,我的旧项目曾经使用 index.php 运行,直到我发现 htaccess :)
猜你喜欢
  • 2017-01-18
  • 2013-04-28
  • 1970-01-01
  • 2019-12-12
  • 2020-07-30
  • 2021-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多