【问题标题】:Htaccess redirect different urls to redirectHtaccess重定向不同的url来重定向
【发布时间】:2016-03-21 14:06:48
【问题描述】:

我正在写一些重定向,因为我们正在更新一个网站,但我们遇到了一些麻烦。

以下是一些重定向的示例网址:

www.website.nl/location/depul.html -> www.website.nl/poppodium-de-pul
www.website.de/location/depul.html -> www.website.de/de_pul
www.website.nl/location/naturereserve.html -> www.website.nl/natuurgebied
www.website.de/location/naturereserve.html -> www.website.de/naturschutzgebiet

不同的语言有不同的网址。所以我必须将 .de url 重定向到 .de 上的页面,将 .nl url 重定向到 .nl 上的页面

我尝试使用 Redirect 301,但似乎无法在要重定向的 url 中使用完整的 url。

Redirect 301 www.website.nl/location/depul.html www.website.nl/poppodium-de-pul

有人知道我能做什么吗?

谢谢

【问题讨论】:

    标签: .htaccess redirect url-redirection


    【解决方案1】:

    在我的索引中使用 php 解决。

    如果有人感兴趣,这是我的代码。

    $redirect_urls = array(
        '/home.html' => array('','','',''),
        '/hotelthing.html' => array('hotel','hotel','lhotel','hotel'),
        '/hotelrooms/singleroom.html' => array('rooms/eenpersoonskamer','rooms/einzelzimmer','rooms/chambre_simple','rooms/single_room'),
        '/hotelrooms/doubleroom.html' => array('rooms/tweepersoonskamer','rooms/doppelzimmer','rooms/chambre_double','rooms/double_room')
        );
    
    if (isset($redirect_urls[$_SERVER['REQUEST_URI']])){
        $tld = strrchr ( $_SERVER['SERVER_NAME'], "." );
        $tld = substr ( $tld, 1 );
    
        if ($tld == 'nl') $sub = 0;
        if ($tld == 'de') $sub = 1;
        if ($tld == 'fr') $sub = 2;
        if ($tld == 'com') $sub = 3;
    
        header('Location: http://' . $_SERVER['SERVER_NAME'] . '/' . $redirect_urls[$_SERVER['REQUEST_URI']][$sub], true, 301);
        exit();
    }
    

    【讨论】:

      【解决方案2】:

      使用这个方法:

      重定向 301 /location/depul.html www.website.nl/poppodium-de-pul

      【讨论】:

      • 我会,但如果它是从 website.NL 请求的,我必须将 /location/depul.html 重定向到 /poppodium-de-pul 但如果它来自网站,它必须重定向到 /de_pul。德国。
      猜你喜欢
      • 2011-03-23
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 2013-02-05
      • 1970-01-01
      • 2018-03-15
      • 1970-01-01
      相关资源
      最近更新 更多