出于 seo 目的使用路由隐藏或删除 url 中的控制器名称 = codeigniter
Hiding or removing controller name in url using routes for seo purpose = codeigniter
我正在使用一个控制器。如何使用路由删除或隐藏 URL 上的控制器名称?
我已经将我的 .htaccess 设置为删除我的 index.php。我已经尝试了很多来自其他类似问题的代码,但我没有运气。我不知道我的实时服务器是否有问题,因为在我之前的项目中我使用了这段代码
$route['del/(:any)'] = "my_cotroller";
$route['(:any)'] = 'pages/view/';
这工作得很好,但是当我试图在我当前的项目中使用它时,它没有工作。
这是我的默认路线
$route['default_controller'] = "my_cotroller";
$route['404_override'] = '';
我想存档 URL 喜欢 http://www.sample.com/login but my current route code gives me this http://www.sample.com/my_controller/login。
感谢您的帮助。
我使用 CI 时的简单方法:
示例控制器:
<?php
class Haha extends CI_Controller
{
public function check()
{
$this->load->view('path/to/check/view');
}
public function choke()
{
$this->load->view('path/to/choke/view');
}
}
示例路线:
//same name with C method
$route['check'] = 'haha/check';
$route['choke/(:any)'] = 'haha/choke';
//or custom route name
$route['squirrel'] = 'haha/check';
$route['woohoo/(:any)'] = 'haha/choke';
我的 htaccess:
RewriteEngine on
RewriteCond !^(index\.php|assets|images|js|css|uploads|favicon.png)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$ ./index.php/ [L]
访问uri:
http://yoursite.com/check
http://yoursite.com/choke/whatever
//or
http://yoursite.com/squirrel
http://yoursite.com/woohoo/whatever
补充:
这是我使用 CI 的旧项目的完整路线,也许你可以得到一些东西。
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['default_controller'] = 'sitehome';
$route['page'] = 'sitehome/page';
$route['page/who-we-are'] = 'site/whoweare';
$route['page/why-use-us'] = 'site/whyus';
$route['page/about-us'] = 'site/about';
$route['page/contact-us'] = 'site/contact';
$route['page/news'] = 'site/news/news';
$route['page/topics'] = 'site/topic';
$route['page/polls'] = 'site/polls';
$route['page/results'] = 'site/result';
$route['agent/detail/(:any)'] = 'site/agentdetail';
$route['register'] = 'site/register';
$route['login'] = 'site/login';
$route['user/home'] = 'usermain';
$route['user/edit-account'] = 'user/editaccount';
$route['user/retire'] = 'user/retired';
$route['user/business/data'] = 'user/business';
$route['user/business/topic/create'] = 'user/topic/topiccreate';
$route['user/business/topic/view'] = 'user/topic/topicview';
$route['user/business/topic/edit/(:num)'] = 'user/topic/topicedit';
$route['user/inbox'] = 'user/inbox';
$route['user/message/read/(:any)'] = 'user/readmessage';
$route['user/provider/list'] = 'user/providerlist';
$route['user/provider/send-message/(:any)'] = 'user/providerlist/sendmessage';
$route['user/notification'] = 'user/notified';
$route['user/inquiry'] = 'user/inquiry';
//testing purpose
$route['percobaan'] = 'coba/percobaan';
$route['poll'] = 'site/polls/retrievePoll';
//serve response
$route['response/single-poll'] = 'api/ResponseData/serveHomePoll';
$route['response/multi-poll'] = 'api/ResponseData/servePoll';
$route['404_override'] = 'notFound';
$route['translate_uri_dashes'] = FALSE;
/* End of file routes.php */
/* Location: ./application/config/routes.php */
备注:
http://example.com/business/
will fail or not exist.
祝你好运。
您可以在 config/routes.php 中定义自定义路由 - 例如:
$route['about'] = 'name_controller/about';
然后,http://example.com/about
转到 http://example.com/name_controller/about
查看更多http://ellislab.com/codeigniter/user-guide/general/routing.html
我正在使用一个控制器。如何使用路由删除或隐藏 URL 上的控制器名称? 我已经将我的 .htaccess 设置为删除我的 index.php。我已经尝试了很多来自其他类似问题的代码,但我没有运气。我不知道我的实时服务器是否有问题,因为在我之前的项目中我使用了这段代码
$route['del/(:any)'] = "my_cotroller";
$route['(:any)'] = 'pages/view/';
这工作得很好,但是当我试图在我当前的项目中使用它时,它没有工作。 这是我的默认路线
$route['default_controller'] = "my_cotroller";
$route['404_override'] = '';
我想存档 URL 喜欢 http://www.sample.com/login but my current route code gives me this http://www.sample.com/my_controller/login。
感谢您的帮助。
我使用 CI 时的简单方法:
示例控制器:
<?php
class Haha extends CI_Controller
{
public function check()
{
$this->load->view('path/to/check/view');
}
public function choke()
{
$this->load->view('path/to/choke/view');
}
}
示例路线:
//same name with C method
$route['check'] = 'haha/check';
$route['choke/(:any)'] = 'haha/choke';
//or custom route name
$route['squirrel'] = 'haha/check';
$route['woohoo/(:any)'] = 'haha/choke';
我的 htaccess:
RewriteEngine on
RewriteCond !^(index\.php|assets|images|js|css|uploads|favicon.png)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$ ./index.php/ [L]
访问uri:
http://yoursite.com/check
http://yoursite.com/choke/whatever
//or
http://yoursite.com/squirrel
http://yoursite.com/woohoo/whatever
补充: 这是我使用 CI 的旧项目的完整路线,也许你可以得到一些东西。
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['default_controller'] = 'sitehome';
$route['page'] = 'sitehome/page';
$route['page/who-we-are'] = 'site/whoweare';
$route['page/why-use-us'] = 'site/whyus';
$route['page/about-us'] = 'site/about';
$route['page/contact-us'] = 'site/contact';
$route['page/news'] = 'site/news/news';
$route['page/topics'] = 'site/topic';
$route['page/polls'] = 'site/polls';
$route['page/results'] = 'site/result';
$route['agent/detail/(:any)'] = 'site/agentdetail';
$route['register'] = 'site/register';
$route['login'] = 'site/login';
$route['user/home'] = 'usermain';
$route['user/edit-account'] = 'user/editaccount';
$route['user/retire'] = 'user/retired';
$route['user/business/data'] = 'user/business';
$route['user/business/topic/create'] = 'user/topic/topiccreate';
$route['user/business/topic/view'] = 'user/topic/topicview';
$route['user/business/topic/edit/(:num)'] = 'user/topic/topicedit';
$route['user/inbox'] = 'user/inbox';
$route['user/message/read/(:any)'] = 'user/readmessage';
$route['user/provider/list'] = 'user/providerlist';
$route['user/provider/send-message/(:any)'] = 'user/providerlist/sendmessage';
$route['user/notification'] = 'user/notified';
$route['user/inquiry'] = 'user/inquiry';
//testing purpose
$route['percobaan'] = 'coba/percobaan';
$route['poll'] = 'site/polls/retrievePoll';
//serve response
$route['response/single-poll'] = 'api/ResponseData/serveHomePoll';
$route['response/multi-poll'] = 'api/ResponseData/servePoll';
$route['404_override'] = 'notFound';
$route['translate_uri_dashes'] = FALSE;
/* End of file routes.php */
/* Location: ./application/config/routes.php */
备注:
http://example.com/business/
will fail or not exist.
祝你好运。
您可以在 config/routes.php 中定义自定义路由 - 例如:
$route['about'] = 'name_controller/about';
然后,http://example.com/about 转到 http://example.com/name_controller/about
查看更多http://ellislab.com/codeigniter/user-guide/general/routing.html