Robin
Robin

Reputation: 164

Htaccess redirect different urls to redirect

I am writing some redirects because we're updating a website but we got to some trouble.

Here are some examples urls to redirect:

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

The different languages have different urls. So i have to redirect the .de url to the page on .de and the .nl url to the page on .nl

I was trying to use Redirect 301 but it seems impossible to use a full url in the to be redirected url.

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

Does anyone know what i can do?

Thanks

Upvotes: 2

Views: 61

Answers (2)

Robin
Robin

Reputation: 164

Solved using php in my index.

Here is my code if anyone is interested.

$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();
}

Upvotes: 2

William Blake
William Blake

Reputation: 1

Use this method:

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

Upvotes: 0

Related Questions