I'd like to acquire some feedback about this. I am unsure whether it's the best approach.

The particulars

I am running Apache 2 with PHP 5.3/MySQL 4 and Drupal 6 may be the platform.

I am creating a site which consists of restaurant reviews over a couple of selected metropolitan areas. Once the customers arrives to begin it may determine which city is their own. I store their choice inside a cookie and when they haven't designed a choice I have selected a default city.

Suggested solution

Now I would like the URL mydomain.com/reviews to redirect towards the city specific URL according to their city choice. For instance mydomain.com/reviews/paris if I have selected Paris as my city. (If there is no cookie place it should redirect towards the default city.)

I think about this the very best alternative because I would like the consumer to have the ability to see reviews in another city without altering their city. Whether they'd like to view reviews for London restaurant they are able to go to mydomain.com/reviews/london.

For top performance I am considering getting Apache look into the cookie making the redirect right city once the user would go to mydomain.com/reviews.

Here are my questions…

  1. How do you configure Apache to get this done?
  2. Is the easiest method to go?
    $city = $_COOKIE['city'];

    header("Location: mydomain.com/reviews/".$city);

You don't have to configure Apache.

  1. To configure Apache to get this done, make use of the following, changing using the cookie title.

    RewriteEngine on
    RewriteCond %{REQUEST_URI} ^/reviews/?$
    RewriteCond %{HTTP_COOKIE} <cookie>=([^;]+)
    RewriteRule .* http://mydomain.com/reviews/%1 [R=302,L]
  2. Yelp stores the place inside a cookie, so I'd take that like a good sign, since there is a lot of traffic and seem to be succeeding.

You will find benefits and drawbacks to presenting Apache to complete the redirect, however the primary disadvantage, is it is simpler to keep the rewrite rule inside your code rather than around the server. You are able to rapidly make fixes and deploy, rather than needing to change and restart all Apache servers.