1

I am busting my head against a wall. I have a created an updated version of a website, and I have various dynamic pages that are being fed through PHP. The old pages had the following rewrites on them through htaccess:

OLD URL BEFORE REWRITE:

/directorio_hoteles/ean/hotel.php?cou=$1&hn=$2&city2=$3

OLD URL AFTER REWRITE:

/directorio_hoteles/Mexico/hotel336813/Villa_Mercedes_Petit_Hotel.htm

HERE IS HOW IT WAS CODED IN THE ORIGINAL HTACCESS:

RewriteRule ^([^/]*)/hotel([^/]*)/([^/]*)\.htm$ ean/hotel.php?cou=$1&hn=$2&city2=$3 [L]

I understand that this original format was not the best way to accomplish this, but this is what I have to work with, and the dynamic url's are already indexed in google. So I need to take the above already rewritten url and redirect (301) it to the new dynamic format which is:

NEW URL BEFORE REWRITE:

directorio-hoteles/index.php?p=hotel-page&a=$1&b=$2&c=$3

NEW URL AFTER REWRITE:

directorio-hoteles/hotel/Mexico/Villa_Mercedes_Petit_Hotel/336813

HERE IS HOW IT IS CODED IN THE NEW HTACCESS FILE:

RewriteRule    ^directorio-hoteles/hotel/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)?$     directorio-hoteles/index.php?p=hotel-page&a=$1&b=$2&c=$3   [NC,L]

So I can not wrap my head around how to get this:

/directorio_hoteles/Mexico/hotel336813/Villa_Mercedes_Petit_Hotel.htm

to redirect to this:

directorio-hoteles/hotel/Mexico/Villa_Mercedes_Petit_Hotel/336813

Any help would be BEYOND appreciated. Thank you in advance for any attempts to solve this issue.

1 Answer 1

1

You can use this rule as first rule in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteRule ^(directorio_hoteles)/([^/]+)/(hotel)([^/]+)/([^.]+)\.htm$ /$1/$3/$2/$5/$4 [L,NC,NE,R=302]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.