检查cookie,并与Apache重定向 [英] Check cookie and redirect with Apache

查看:146
本文介绍了检查cookie,并与Apache重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很想得到这方面的一些反馈。我不知道这是否是正确的做法。

详情

我运行的Apache 2的PHP 5.3 / MySQL的4和Drupal 6的平台。

我正在开发,其中包含在几个选定的城市的餐厅评论网站。
当用户到达现场就可以选择哪个城市是他们的。我自己的选择存储在cookie中,如果他们还没有做出选择,我选择了一个默认的城市。

建议的解决方案

现在我想要的网址mydomain.com/reviews重定向到基于自己的城市选择城市的具体URL。例如,如果我选择了巴黎作为我的城市mydomain.com/reviews/paris~~V。
(如果没有设置Cookie应该重定向到默认的城市。)

我认为这是最好的选择,因为我希望用户能够看到在另一个城市的评价不改变自己的城市。如果他们想查看的伦敦餐厅的评论,他们可以直接去mydomain.com/reviews/london~~V。

有关我想有阿帕奇检查Cookie,并重定向到一个合适的城市,当用户进入mydomain.com/reviews的最佳性能。

因此,这里是我的问题...


  1. 如何配置Apache要做到这一点?

  2. 这是去的最佳途径?


解决方案

  1. 要配置Apache要做到这一点,请使用下,与Cookie名称替换。

      RewriteEngine叙述上
    的RewriteCond%{REQUEST_URI} ^ /评论/ $?
    的RewriteCond%{HTTP_COOKIE}<&饼干GT =([^;] +)
    重写规则。* http://mydomain.com/reviews/%1 [R = 302,L]


  2. Yelp的存储在cookie中的位置,所以我把它看作一个好兆头,因为他们有一吨的交通,而且似乎做得很好。


有优点和缺点,使用Apache做重定向,但主要的骗子,就是它更容易维护重写规则在code,而不是在服务器上。您可以迅速使修复和部署,而不必改变并重新启动所有的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?

解决方案

  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.

这篇关于检查cookie,并与Apache重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆