Joomla Custom Component redirection after login to SEF URL

536 Views Asked by At

So I've build a custom component that pretty much serves as customer dashboard which can only be accessed by login. To check whether a customer is logged in and redirection to the login page is required I did this:

<?php
  $user       = JFactory::getUser();
  $app          = JFactory::getApplication();
?>
<?php
  if($user->id != 0) {
     // My dashboard content
  } else {
   $message = "Please login!";
   $url = JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode('index.php?option=com_mydashboard&view=dashboard');
   $app->redirect($url, $message);
  }
?>

Now this works almost perfectly. However, once the user is logged in and redirected it is redirected to the ' index.php?option=com_mydashboard&view=dashboard ' page where the module that I've assigned to /dashboard (the SEF URL) is not showing up. Clicking on the dashboard menu item again does show it but requires a not so logical step for the customer. How can a make the redirect to return to the /dashboard page instead of the non-SEF URL?

1

There are 1 best solutions below

0
On

Ok, so best way to deal with this is add a custom redirect in for example your htaccess file. Problem solved!