首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >代码触发器清理URL

代码触发器清理URL
EN

Stack Overflow用户
提问于 2013-08-15 00:22:18
回答 2查看 1.6K关注 0票数 2

我正在处理这个URL。我正在做一个项目,我有这个URL:

代码语言:javascript
复制
http://localhost/franca/menkenPh/index.php/controller/argument/argument

但我需要我变成这样的人:

代码语言:javascript
复制
http://localhost/franca/menkenPh/0/cirug

我怎样才能做到这一点呢?

我试着在.htaccess上这样做:

代码语言:javascript
复制
<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时,我希望它给我页面未找到错误,并且当我这样做时:

代码语言:javascript
复制
    http://localhost/franca/menkenPh

它告诉我,参数被遗漏了。

有什么线索吗?

EN

回答 2

Stack Overflow用户

发布于 2013-08-15 00:25:41

转到您的应用程序/config/config.php,从基本url中删除index.php。

代码语言:javascript
复制
/*
|--------------------------------------------------------------------------
| 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'] = '';

然后转到您的路线添加

代码语言:javascript
复制
$route['/(:any)/(:num)'] = "maincontroller/index/$1/$2";

因此该方法应该是index(),但根本没有参数,只需使用uri类并定位这两个uri段

代码语言:javascript
复制
$arg1 = $this->uri->segment(3,0);
$arg2 = $this->uri->segment(4,0);

你的重写基础应该是

代码语言:javascript
复制
RewriteBase /franca/menkenph/
票数 0
EN

Stack Overflow用户

发布于 2013-08-15 00:51:22

代码语言:javascript
复制
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /franca/menkenPh/index.php?/$1 [L]

试试这个htaccess

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18237126

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档