dongyuyi5680 2011-05-16 18:14
浏览 310
已采纳

检查cookie并使用Apache重定向

I'd love to get some feedback on this. I'm not sure if it's the right approach.

The details

I'm running Apache 2 with PHP 5.3/MySQL 4 and Drupal 6 is the platform.

I'm developing a site which contains restaurant reviews in a couple of selected cities. When the users arrives at the site it can choose which city is theirs. I store their choice in a cookie and if they haven't made a choice I've selected a default city.

Proposed solution

Now I want the URL mydomain.com/reviews to redirect to the city specific URL based on their city choice. For example mydomain.com/reviews/paris if I've selected Paris as my city. (If there's no cookie set it should redirect to the default city.)

I consider this the best alternative because I want the user to be able to see reviews in another city without changing their city. If they'd like to view reviews for London restaurant they can simply go to mydomain.com/reviews/london.

For the best performance I'm thinking of having Apache check the cookie and make the redirect to the right city when the user goes to mydomain.com/reviews.

So here are my questions…

  1. How do I configure Apache to do this?
  2. Is this the best way to go?
  • 写回答

3条回答 默认 最新

  • drnf09037160 2011-05-16 18:56
    关注
    1. To configure Apache to do this, use the following, replacing with the cookie name.

      RewriteEngine on
      RewriteCond %{REQUEST_URI} ^/reviews/?$
      RewriteCond %{HTTP_COOKIE} <cookie>=([^;]+)
      RewriteRule .* http://mydomain.com/reviews/%1 [R=302,L]
      
    2. Yelp stores the location in a cookie, so I'd take that as a good sign, since they have a ton of traffic and appear to be doing well.

    There are pros and cons to using Apache to do the redirect, but the main con, is that it is easier to maintain the rewrite rule in your code instead of on the server. You can quickly make fixes and deploy, instead of having to change and restart all Apache servers.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题