URL 通过 .Htaccess 重定向在 Php Codeigniter 中不起作用

URL Redirect through .Htaccess doesn't work in Php Codeigniter

我想当我输入 localhost/projectname/index.html 时它会重定向到

http://localhost/service/welcome/index

为此,我在 .htaccess 中写了它,但它不起作用

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L] 
</IfModule>

Redirect /index.html http://localhost/service/welcome/index

我该怎么做?

在 codeigniter 中 没有文件在 URL 中调用 。 Codeigniter 所做的就是使用 MVC 结构 来呈现视图。

以及如果您访问根文件夹(index.html 或 index.php)上的任何内容,它将重定向到应用程序文件夹。然后默认控制器是 Trigger out。

cz在根目录下有文件调用index.php,可以看到

$application_folder = 'application';
$system_path = 'system';

你可以看看这个

  1. 路线 - config/routes.php
  2. 控制器 - controller/
  3. 型号 - model/
  4. 查看 - view/

我们使用 .htaccess 删除 URL 中的 index.php

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/ [L] 
</IfModule>

如果您想在 URL

末尾添加 .html.php

config/config.php

/*

  |--------------------------------------------------------------------------

  | URL suffix

  |--------------------------------------------------------------------------

  |

  | This option allows you to add a suffix to all URLs generated by CodeIgniter.

  | For more information please see the user guide:

  |

  | http://codeigniter.com/user_guide/general/urls.html

 */
$config['url_suffix'] = '';