Php codeigniter的Url重写

Php codeigniter的Url重写,php,Php,如何使用.htaccess或CI路由重写网站的特定url 作为 或者尝试htaccess RewriteEngine On RewriteRule ^([^/]*)$ /user_controller/newfunction/$1 [L] /application/config/routes.php $route['/all/other/routes/must/come/first!'] = "wherever/you/want"; $route['/(:any)'] = "/user_c

如何使用.htaccess或CI路由重写网站的特定url

作为

或者尝试htaccess

RewriteEngine On
RewriteRule ^([^/]*)$ /user_controller/newfunction/$1 [L]

/application/config/routes.php

$route['/all/other/routes/must/come/first!'] = "wherever/you/want";
$route['/(:any)'] = "/user_controller/newfunction/$1";
$route['(:any)'] = 'user_controller/newfunction/$1';

在application/config/routes.php中可以找到更易于使用的CI路由系统

$route['/all/other/routes/must/come/first!'] = "wherever/you/want";
$route['/(:any)'] = "/user_controller/newfunction/$1";
$route['(:any)'] = 'user_controller/newfunction/$1';
不要忘记在application/config/config.php上设置基本url

$config['base_url'] = 'http://www.domain.com/';
添加并记住删除url中的index.php。在站点的根目录下编辑.htaccess文件

RewriteEngine on
RewriteCond $1 !^(index\.php|assets|_searches|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]
现在,在用户_控制器中,函数newfunction如下所示:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class user_controller extends CI_Controller {

    public function __construct() {
        parent::__construct();
        // load things like models, libraries, helpers
    }

    function newFunction($slug)
    {
        echo 'hello my name is'.$slug;
    }
}

页面未正确重定向。显示网站的其他URL时出错。请举例说明第一个问题。当尝试访问网站的其他控制器时,页面未正确重定向。请在下面找到错误。Firefox检测到服务器正在以一种永远无法完成的方式重定向对此地址的请求。是否有其他方法来执行htis,我只想对此url进行更改,而不是对网站的所有url进行更改?该页面没有正确重定向,错误显示为其他网站的url。您应该在两者之间保留一些内容,如as,但我想在此显示此特定控制器的like domain.com/username。