代码点火器清理URL

时间:2013-08-14 16:22:18

标签: php codeigniter mod-rewrite

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

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时,我希望它给我找不到页面错误,当我这样做时:

    http://localhost/franca/menkenPh

它告诉我错过了论点。

有任何线索吗?

2 个答案:

答案 0 :(得分:0)

转到你的应用程序/ config / config.php从基本网址中删除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/

答案 1 :(得分:0)

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

试试这个htaccess