phpmysqlhttp-redirectdatabase-driven

Database driven website dynamic redirect


Good morning,

I am working on a site that will compare two things on each page dynamically from mysql through php. For examples sake, lets say its comparing travel destinations. An example url from one of these pages would be "http://sometravelwebsite.com/destinations/compare/New-York-City-vs-Tokyo"

The way the php is written, the order of the cities does not matter. If you enter

../New-York-City-vs-Tokyo

you will get the same information as if you entered

../Tokyo-vs-New-York-City 

The only difference is which city's information is on the left side, and which city's information is on the right.

For SEO purposes, it would be better if there was only one version of the page, with the other url redirecting to the main url (e.g. ../New-York-City-vs-Tokyo is the main url that is indexed by Google, but if the other url: ../Tokyo-vs-New-York-City is entered, it 301 redirects to the main url).

My question is: Can this be done dynamically?

The only thing I can think of is to use an autoincrementing index in the mysql database and always put the city with a lower index number on the left, and the city with a higher index number on the right.

That said, I would prefer if I had some control over which city was on which side of the page. While I'm not going to go through and decide which city goes on which side for EVERY comparison (which would get crazy the more cities that were added), I would like to have control over some of them in order to put the city with the more desirable characteristics on the left side of the page where it will be seen first (assuming individuals are reading left to right).

Can anyone think of a better way to do this dynamically through either php, mysql, .htaccess or any other way?

Any help would be greatly appreciated!


Solution

  • The dynamic PHP handles both but if they come from a search engine you want a redirect? Stick to a simple naming convention or always order them in alphabetically order or something that way you won't have separate variations. Im sure Google won't mind if its 'A Vs B' or 'B Vs A' im sure it would return both equally if useful to the search.

    You can can put the better performing object on the left. Make the URL always alphabetically, put the 2 cities (or more) into array and sort alphabetically. As for displaying on the page, query your database and display them left to right(Sort on your MySQL Statement) based on the calculated 'score' of the one you think will convert higher.