基于cookie值的mod_rewrite [英] mod_rewrite based on cookie value

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

问题描述

我有一个多语言网站,我需要根据cookie值更改URL.

I have a multilingual website and I need change the URL based on a cookie value.

例如,我有 $ _ COOKIE ["lang"] ="en" ,并且我想将URL更改为 www.mydomain.com/en/rest/of//url en.mydomain.com/rest/of/the/url .

For example, I have $_COOKIE["lang"] = "en" and I want to change the URL to either www.mydomain.com/en/rest/of/the/url or en.mydomain.com/rest/of/the/url.

我该怎么做?

推荐答案

使用任何可用的重定向.在香草php中,您可以使用 header().

Use any kind of redirect available to you. In vanilla php you can user header().

mod_rewrite是一个基于Web服务器的指令,它可以在您的PHP脚本有机会加入之前运行良好,并且绝对不能触摸cookie.

mod_rewrite is a webserver-based directive, it works well before your php script gets a chance to kick in, and it most definitely cannot touch cookies.

更新:实际上,您可以使用mod_rewrite中的cookie(实用链接此处).但是,我不建议这样做,并且会破坏代码调试-很少有人会想到在.htaccess中寻找基于cookie的重定向.

Update: You CAN, in fact, use cookies from mod_rewrite (practical link here, official docs here). I do not, however, recommend it as can and will ruin code debugging - few people will think of looking in .htaccess for cookie-based redirects.

这篇关于基于cookie值的mod_rewrite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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