2016-03-21 103 views
2

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

下面是一些例子的URL重定向:

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 

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

我试图使用重定向301,但它似乎不可能使用完整的url重定向的网址。

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

有谁知道我能做些什么?

感谢

回答

2

在我的索引使用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(); 
} 
0

使用此方法:

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

+0

我想,但我如果是从website.NL请求重定向到/location/depul.html/poppodium-DE-PUL但它重定向到/ de_pul如果它来自website.DE。 – Robin