I'm developping a website using CI and today I'm facing a problem . Here is my link .
http://example.com/subfolder/site/page/Snowman_Trek_24_Days
i want to change my link like
http://example.com/subfolder/Snowman_Trek_24_Days
i update my config file -
$config['uri_protocol'] = 'QUERY_STRING';
$config['enable_query_strings'] = TRUE;
also i tested this -
$config['uri_protocol'] = 'PATH_INFO';
$config['enable_query_strings'] = TRUE;
In route.php file i used this code -
$route['default_controller'] = 'site';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['page/(:any)'] = "site/page/$1";
My htaccess code is :-
RewriteEngine On
RewriteBase /folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
After doing all this i am getting this error :- Unable to determine what should be displayed. A default route has not been specified in the routing file.Can anybody help me .
Try with this: in your .htaccess
file put
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]
Now all your request should avoid subfolder segment in URL. But also you have to design URLs in APPPATH.'config/config.php'
file and in controller to have:
$route['(:any)'] = "site/page/$1";
So
http://example.com/subfolder/Snowman_Trek_24_Days
should be valid path. Be aware of (:any)
wildcard because it will reroute any other request not site/page/$1
only and has to be at the end of routes.php
file. Any other routes you want to execute, you have to put before that one explicitly. Example:
$route['login'] = 'auth/login';
$route['about'] = 'staticpage/about';
$route['contact'] = 'staticpage/contact';
$route['(:any)'] = "site/page/$1";
More of routing in docs .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.