问题
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