首页 > 解决方案 > uri段2中不允许nuber值,codeigniter

问题描述

我已将 .htaccess 配置为

    RewriteEngine on
    RewriteBase /
    RewriteCond $1 !^(index\.php|static|robots\.txt|favicon\.ico|uploads|assets|img|uploaded|admin|source|images|googlexxxxxxxx\.html|mobile.html)
    RewriteRule ^(.*)$ index.php/$1 [L]

我的路由是:

    $route['career/(:any)'] = 'career/index/$1';

我的网址是:

    http://local.berger.com/career/4

但是说找不到页面。但如果我只保留网址http://local.berger.com/career/那就没问题了。我们不能将数字放在 uri 段 2 中,还是 .htaccess 有问题?任何形式的建议表示赞赏。谢谢。

标签: .htaccessurl-rewritingurl-routingcodeigniter-3

解决方案


首先使用普通的 .htaccess 在这里你可以得到。

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

之后你的配置文件

$config['index_page'] = 'index.php';

用。。。来代替

$config['index_page'] = '';

你的路线没问题

$route['career/(:any)'] = 'career/index/$1';

现在你的控制器

public function index($variable){
    //code goes here
}

现在你可以走了。希望对你有效。


推荐阅读