我如何修复 codeigniter 3 的路由?
How can i fix routes of codeigniter 3?
有些东西不起作用,我的 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/';
$route['cities']['post'] = 'cities/index';
$route['cities/(:num)']['put'] = 'cities/index/';
$route['cities/(:num)']['delete'] = 'cities/index/';
我的 .htaccess 是这样的
Options FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
这里的问题是,当我转到 googleChrome 并输入 url 时,如下所示:....www.domain.com.mx/project-server/
它将我发送到默认控制器,它是书籍、欢迎或任何地方。
但是当我想像这样在 url 上输入它时
...www.domain.com.mx/project-server/书籍
出现这样的错误:
在此服务器上找不到请求的 URL /project-server/cities。
这是我在 github 中的项目
https://github.com/cmurra/project-server
将您的 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 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/ [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
就是其中之一
您可能还想检查一下配置
$route['translate_uri_dashes'] = TRUE;
尝试将其设置为 FALSE(您的 URL domain.com.mx/project-server/books)
https://www.codeigniter.com/userguide3/general/routing.html
有些东西不起作用,我的 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/';
$route['cities']['post'] = 'cities/index';
$route['cities/(:num)']['put'] = 'cities/index/';
$route['cities/(:num)']['delete'] = 'cities/index/';
我的 .htaccess 是这样的
Options FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
这里的问题是,当我转到 googleChrome 并输入 url 时,如下所示:....www.domain.com.mx/project-server/
它将我发送到默认控制器,它是书籍、欢迎或任何地方。 但是当我想像这样在 url 上输入它时
...www.domain.com.mx/project-server/书籍 出现这样的错误: 在此服务器上找不到请求的 URL /project-server/cities。
这是我在 github 中的项目 https://github.com/cmurra/project-server
将您的 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 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/ [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
就是其中之一
您可能还想检查一下配置
$route['translate_uri_dashes'] = TRUE;
尝试将其设置为 FALSE(您的 URL domain.com.mx/project-server/books)
https://www.codeigniter.com/userguide3/general/routing.html