[英]How to remove class name and controller name from url in codeigniter?
我正在使用CI开发网站,今天却遇到了问题。 这是我的链接。
http://example.com/subfolder/site/page/Snowman_Trek_24_Days
我想像这样更改我的链接
http://example.com/subfolder/Snowman_Trek_24_Days
我更新我的配置文件-
$config['uri_protocol'] = 'QUERY_STRING';
$config['enable_query_strings'] = TRUE;
我也测试了-
$config['uri_protocol'] = 'PATH_INFO';
$config['enable_query_strings'] = TRUE;
在route.php文件中,我使用了以下代码-
$route['default_controller'] = 'site';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['page/(:any)'] = "site/page/$1";
我的htaccess代码是:-
RewriteEngine On
RewriteBase /folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
完成所有这些操作后,我得到此错误:-无法确定应显示的内容。 尚未在路由文件中指定默认路由。有人可以帮助我吗?
试试这个:在您的.htaccess
文件中
RewriteEngine On
RewriteBase /subfolder/# is this subfolder from URL we are speaking about?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^subfolder/(.*)$ index.php?/subfolder/$1 [QSA,L]
现在,您的所有请求都应避免URL中的子文件夹段。 但是,您还必须在APPPATH.'config/config.php'
文件和控制器中设计URL,以便具有:
$route['(:any)'] = "site/page/$1";
所以
http://example.com/subfolder/Snowman_Trek_24_Days
应该是有效路径。 请注意(:any)
通配符,因为它会重新路由任何其他请求,而不仅是site/page/$1
而且必须位于routes.php
文件的末尾。 您要执行的任何其他路由,都必须明确地放在该路由之前。 例:
$route['login'] = 'auth/login';
$route['about'] = 'staticpage/about';
$route['contact'] = 'staticpage/contact';
$route['(:any)'] = "site/page/$1";
文档中的更多路由。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.