【问题标题】:Code Igniter Clean URLCodeigniter 清理 URL
【发布时间】:2013-08-14 16:22:18
【问题描述】:

我正在处理这个 URL。我正在开发一个拥有此 URL 的项目:

http://localhost/franca/menkenPh/index.php/controller/argument/argument

但我需要我变成这样的东西:

http://localhost/franca/menkenPh/0/cirug

我怎样才能做到这一点?

我尝试在 .htaccess 上执行此操作:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /franca/menkenph/
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

但是当我转到 URL 时,我希望它给我 page not found 错误,当我这样做时:

    http://localhost/franca/menkenPh

它告诉我参数被遗漏了。

有什么线索吗?

【问题讨论】:

标签: php codeigniter mod-rewrite


【解决方案1】:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /franca/menkenPh/index.php?/$1 [L]

试试这个htaccess

【讨论】:

    【解决方案2】:

    转到您的 application/config/config.php 从基本 url 中删除 index.php。

    /*
    |--------------------------------------------------------------------------
    | Base Site URL
    |--------------------------------------------------------------------------
    |
    | URL to your CodeIgniter root. Typically this will be your base URL,
    | WITH a trailing slash:
    |
    |   http://example.com/
    |
    | If this is not set then CodeIgniter will guess the protocol, domain and
    | path to your installation.
    |
    */
    $config['base_url'] = 'http://localhost/franca/menkenPh';
    
    /*
    |--------------------------------------------------------------------------
    | Index File
    |--------------------------------------------------------------------------
    |
    | Typically this will be your index.php file, unless you've renamed it to
    | something else. If you are using mod_rewrite to remove the page set this
    | variable so that it is blank.
    |
    */
    $config['index_page'] = '';
    

    然后去你的路线添加

    $route['/(:any)/(:num)'] = "maincontroller/index/$1/$2";
    

    所以方法应该是 index() 但根本没有参数只是使用 uri 类并找到这两个 uri 段

    $arg1 = $this->uri->segment(3,0);
    $arg2 = $this->uri->segment(4,0);
    

    你的重写基础应该是

    RewriteBase /franca/menkenph/
    

    【讨论】:

    • 对不起,我没有说,但我有这条路线:$route['site/(:any)'] = 'site/index/$1';
    • 抱歉,cirug 是一个参数,我需要的 URL 是 controller/argument/argument :)
    • 对不起,但是像什么?
    • 不,我认为 mod rewrite 是行不通的。如果我这样做:localhost/franca/menkenPh 它会转到 mainController 但如果我向该 URL 添加一些内容,我不知道它要去哪里,寻找另一个控制器?
    • 我认为您还必须将 mainController 定义为默认控制器
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 2017-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多