Im having trouble trying to make routes work on the production system(nginx). It works on localhost which is running apache.
File structure
/var/www/example.com
--application
--system
adm
--application
--system
--controller
--user
--example
--model
--users_model
--views
--admin/
--login
--signup_form
--example
I keep getting 404 error when trying to access the controller from adm folder.
My routes
$route['default_controller'] = 'user';
$route['404_override'] = '';
/*admin*/
$route['admin'] = 'user/index';
$route['admin/signup'] = 'user/signup';
$route['admin/create_member'] = 'user/create_member';
$route['admin/login'] = 'user/index';
$route['admin/logout'] = 'user/logout';
$route['admin/login/validate_credentials'] = 'user/validate_credentials';
user controller view is displayed just the static content and everything else gives 404.
/var/www/example.com/adm/application/config/config.php
base_url = http://example.com/adm
uri_protocol = AUTO
Any help would be greatly appreciated, TIA.
You have to add index.php after your project folder like:
www.site.com/project/index.php/user/signup
If you want to access your site without index.php then see this post CodeIgniter removing index.php from url
Related
I have created a multi-language website.
Facing issue while creating SEO user-friendly URL.
current URL:
http://localhost/example/en/user/myaccount OR
http://localhost/example/fr/user/myaccount
want to change it with
http://localhost/example/en/myaccount OR
http://localhost/example/fr/user/myaccount
routes.php
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
// URI like '/en/about' -> use controller 'about'
$route['^(en|de|fr|nl|id|es)/(.+)$'] = "$2";
// '/en', '/de', '/fr','/es' and '/nl' URIs -> use default controller
$route['^(en|de|fr|nl|id|es)$'] = $route['default_controller'];
also tried with
$route["myaccount"] = "user/myaccount";
$route["^(en|de|fr|nl|id|es)$/myaccount"] = "user/myaccount";
Nothing will work in this case. Already used following in routes.php file other demo projects with out multi-language. There it's work perfectly.
$route["myaccount"] = "user/myaccount";
Thanks in advance
you can consult the documentation for routes here
https://www.codeigniter.com/user_guide/general/routing.html
and for your problem
$route["(:any)/myaccount"] = "user/myaccount/$1";
I created the URL in route.php like
www.domainname/companyname - Its Work properly
And i also created the URL like
www.domainname/events - Its also works good.
But I created the URL like
www.domainname/category/1 - Its shows error
$route["(.*)"] = 'controller/productsname/$1';
$route['Admin'] = 'Admin/login';
$route["category/:num"] = 'controller/category/$1';
$route["(.*)"] = 'controller/productsname/$1';
Thanks
I haven't tried it yet, but you will probably need to simply point all urls to it, naturally after the rules you've already added.
So something like:
$route['Admin'] = 'Admin/login';
$route["category/:num"] = 'controller/category/$1';
$route["(:any)/(:num)"] = 'controller/$1/$2';
//or
$route["(:any)/(:num)"] = 'controller/products/$1/$2';
I am developing a single page web site so all routes should lead to the default router. This is how I've achieved that through the routes.php file:
$route['default_controller'] = "home";
$route['404_override'] = '';
$route['admin'] = 'admin/home';
$route['^/'] = "home";
$route['(.*)'] = $route['default_controller'];
Thats working as expected on a test server and on the local host, but on the actuall server, when I try to find any of the pages I am getting the 404 error. Any ideas what could be wrong?
$route['default_controller'] = "home";
$route['404_override'] = "home/index";
$route['.*'] = "home/index/$1"
I installed HMVC by wiredesignz but the routes from application/modules/xxx/config/routes.php didn't get recognized at all.
Here is an example:
In application/modules/pages/config/routes.php I have:
$route['pages/admin/(:any)'] = 'admin/$1';
$route['pages/admin'] = 'admin';
If I type the URL, domain.com/admin/pages/create it is not working, the CI 404 Page not found appears.
If I move the routes to application/config/routes.php it works just fine.
How do I make it work without putting all the admin routes in main routes.php?
I searched the web for over 4 hours but found no answers regarding this problem. I already checked if routes.php from modules is loading and is working just fine, but any routes I put inside won't work.
I found a way of making the routes from modules working just fine, I don't know if is the ideal solution but works fine so far:
open your application/config/routes.php and underneath $route['404_override'] = ''; add the following code:
$modules_path = APPPATH.'modules/';
$modules = scandir($modules_path);
foreach($modules as $module)
{
if($module === '.' || $module === '..') continue;
if(is_dir($modules_path) . '/' . $module)
{
$routes_path = $modules_path . $module . '/config/routes.php';
if(file_exists($routes_path))
{
require($routes_path);
}
else
{
continue;
}
}
}
the following solution works fine even if config folder or routes.php is missing from your module folder
Here's the thing: the module's routes.php only gets loaded when that module is "invoked", otherwise CI would have to load all route configurations from all modules in order to process each request (which does not happen).
You'll have to use your main application's routes.php to get this to work. You aren't using the pages segment in your URL, therefore the routing for that module never gets loaded.
I know that's what you wanted to avoid, but unfortunately it's not possible unless you want to get "hacky".
Here's the routing I use to map requests for admin/module to module/admin, maybe you can use it:
// application/config/routes.php
$route['admin'] = "dashboard/admin"; // dashboard is a module
$route['admin/([a-zA-Z_-]+)/(:any)'] = "$1/admin/$2";
$route['admin/([a-zA-Z_-]+)'] = "$1/admin/index";
$route['(:any)/admin'] = "admin/$1";
You just need this https://gist.github.com/Kristories/5227732.
Copy MY_Router.php into application/core/
index.php
$admin_cookie_code="1234567890";
setcookie("JoomlaAdminSession",$admin_cookie_code,0,"/");
header("Location: /administrator/index.php");
.htaccess file
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/administrator
RewriteCond %{HTTP_COOKIE} !JoomlaAdminSession=1234567890
RewriteRule .* - [L,F]
i used this code but it's not working...
page will be redirect to administrator but www.domain.com/administrator is also accessable
I got tired of searching an answer for this one and just made a PHP code that will redirect if the visitor gets into the /administration folder without the security key or as a registered user:
Just place this code at the end of the index.php file on your administration folder (/administration/index.php) before the 'echo' instruction:
/* Block access to administrator
--------------------------------------------- */
$user =& JFactory::getUser();
$secretkey = 'mysecretkey';
$redirectto = 'location: yourdomainurlhere';
$usertype = 'Registered';
//Check if the user is not logged in or if is not a super user:
if ($user->guest || (!$user->guest && $user->usertype != $usertype) ) {
//Check if the secret key is present on the url:
if (#$_GET['access'] != $secretkey) { header($redirectto); }
}
/* --------------------------------------------- */
After you will be only able of accessing your site using:
mysite.com/administrator/?access=mysecretkey
Tested on Joomla 1.5 and Jooma 2.5, worked well for both.
I explain it a little bit more on my page:
https://www.infoeplus.com/protect-your-joomla-administrator-folder/
Are you trying to hide the administrator URL ? Here is what I'm using :
http://extensions.joomla.org/extensions/access-a-security/site-security/login-protection/15711
You can find more extensions here : http://extensions.joomla.org/extensions/access-a-security/site-security/login-protection
http://extensions.joomla.org/extensions/access-a-security/site-security/login-protection
you can use this protect your admin login.
this is really esay and nice extension.