mod_rewrite based on cookie value

て烟熏妆下的殇ゞ 提交于 2021-01-29 03:51:26

问题


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

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.

How can I do this?


回答1:


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

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.

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.



来源:https://stackoverflow.com/questions/16894764/mod-rewrite-based-on-cookie-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!