简体   繁体   English

Joomla开始和语言重定向

[英]Joomla Start and Language Redirections

I have two questions with my Joomla! 我的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. 我想为我的域设置标准重定向,因此当用户在domain.com中键入内容时,他将被重定向到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. 我的第二个问题是,是否可以使用用户浏览器语言进行标准语言重定向,例如,如果他是德语并输入domain.com/menu-item,他将被重定向到domain.com/de/menu-item ,这是他进入我项目的每个页面上的内容。

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! Joomla版本:Joomla! 3.8.10 Stable 3.8.10稳定
  2. PHP Version: 7.0.30-0+deb9u1 PHP版本: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 马格努斯问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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