简体   繁体   中英

Joomla Start and Language Redirections

I have two questions with my Joomla! Project:

  • I want to have a standard redirect for my domain, so when a user types in domain.com he will be redirected to domain.com/my-joomla-menu-item. This cannot be done with the standard Home Menu item because my setup doesn't allow this.
  • My second question is if it is possible to make a standard language redirect with the users browser language, so for example if he is German and enters domain.com/menu-item, he gets redirected to domain.com/de/menu-item, and this on every page he enters on my project.

I would be very happy if someone can help me. Big thanks in advance and have a nice day,

Magnus

Technical Specs:

  1. Joomla Version: Joomla! 3.8.10 Stable
  2. PHP Version: 7.0.30-0+deb9u1

Okay, i found a solution myself. I post the code below so if someone is searching for something like this he can have a look at it.

For the start redirect:

<?php
    $currentLink = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    if ($currentLink == "https://example.com") {
        header("Location: https://example.com/cool-submenu");
    }
    if ($currentLink == "https://example.com/") {
        header("Location: https://example.com/cool-submenu");
    }
?>

For the language redirect:

<?php
    $url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
    $path = parse_url($url, PHP_URL_PATH);
    $pathFragments = explode('/', $path);
    $end = end($pathFragments);
    if ($lang == "de") {
        header("Location: https://example.com/de/{$end}");
    }
?>

I hope this helps if someone needs it.

Greets, Magnus

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM