Default Controller not loading after rerouting
What you appear to be doing is looking for a controller with the 'sitename' you are passing through. So if you navigate to site.com/sites/my-site/
you route tells it to look for a controller called my-site and run the index method.
The value of the route should be a path to an actual controller / method pair.
$route['sites/([^/]+)/(.*)'] = '$2';
should be
$route['sites/([^/]+)/(.*)'] = 'sites/index/$1/$2';
This is assuming it's the index method that accepts the sitename as it's first parameter in your sites controller.
It's not totally clear what you're asking, but heres a shot:
You need to create an .htaccess
file in the root of your site (i.e. in the same folder that your system
folder is in). In that file:
<IfModule mod_rewrite.c>RewriteEngine onRewriteCond $1 !^(index\.php)RewriteRule ^(.*)$ index.php/$1 [L]</IfModule>
See the "Remove the index.php file" section of this page: http://codeigniter.com/user_guide/general/urls.html for more info.
Also, the route
that you're using would make it so that when you go to www.site.com
, you will see www.site.com/sites/content
.
With the url www.site.com/sites/sitename/content/
, sites
is your controller, sitename
the method or function, and content
would be considered a parameter to the sitename
function -- this won't work like it seems like you want, but I can't be sure without seeing your controller.
Maybe edit your question and add your controller(s), and we can be of more assistance.
UPDATE:
1: $config['base_url']
has nothing to do with routing or which controller is being used, so this is making your question harder to understand.
2: It isn't clear what you are trying to accomplish (sorry).
By idea when I go to
www.site.com/sites/sitename/
the default controller is not loading.
According to the CI user guide:
CodeIgniter can be told to load a default controller when a URI is not present, as will be the case when only your site root URL is requested. To specify a default controller, open your application/config/routes.php file and set this variable:
So, what this means is that the default_controller
is used only when there is no URI present. In other words: the default controller only applies when the URL is www.site.com, and in no other case will it be used (unless you are using sub-folders in the controllers folder -- see below).
If you trying to make it so that each of your sites has its' own controller, you could use subfolders in your controller folder.
In routes.php:
$route['sites/(:any)'] = "$1";$route['default_controller'] = "content";
Then your folder structure:
So you have your controller folder. In it, create a folder for each site. In each of those controllers create your default controller (named content.php in the above image).
With this setup, www.site.com/sites/site1
will call the default controller (content
) from application/controllers/site1/content.php
and show the index
function of that controller.
If you then want to call other functions of the site1 controller, the URL would look like:www.site.com/sites/site1/content/otherFunction
.
Hope this helps.
$uri_string=$_SERVER['REQUEST_URI']; $way=explode('/',$uri_string); /// print_r($way);//echo $way[3]; if($way[1]=="sites" and strlen($way[2])>2 and strlen($way[3])<1){ echo "JAJA ";$route['sites/:any'] = "content/show_page/home"; } else{ $route['sites/([^/]+)/(.*)'] = '$2'; }
this was solution. thanks all who answered. thanks stormdrain. you pointed me to a write direction in your routing example. Thanks