如何根据cookie从.htaccess添加到我的URL

时间:2022-10-30 10:33:17

I have a site that is creating a cookie based on a users geoIP, so that the location is always part of the URL, like example.com/dc-metro/fly-a-kite. I am having an issue when a user comes to example.com/fly-a-kite and inserting the correct location to the URL. Here is what I have in my .htaccess file:

我有一个基于用户geoIP创建cookie的站点,因此该位置始终是URL的一部分,例如example.com/dc-metro/fly-a-kite。当用户访问example.com/fly-a-kite并将正确的位置插入URL时,我遇到了问题。这是我在.htaccess文件中的内容:

RewriteCond %{HTTP_COOKIE} market=([dc-metro]) [NC]
RewriteRule ^fly-a-kite(.*)$ /dc-metro/fly-a-kite$1 [L,R=301]

RewriteCond %{HTTP_COOKIE} market=([chicago]) [NC]
RewriteRule ^fly-a-kite(.*)$ /chicago/fly-a-kite$1 [L,R=301]

I am using MODX, which I don't think should make a difference, the problem I am having is that when I try going directly to example.com/fly-a-kite it is inserting different locations other than what should be my saved cookie.

我正在使用MODX,我认为不应该有所作为,我遇到的问题是,当我尝试直接访问example.com/fly-a-kite时,它会插入不同的位置而不是应该保存的内容曲奇饼。

Thank you for any help you can provide.

感谢您提供任何帮助。

1 个解决方案

#1


I found a solution last night that is working, not sure if it is the best answer, but it is working for me. Instead of using ([name]) for the cookie value I got rid of the ([ ]) so my htaccess looks like:

我昨晚找到了一个有效的解决方案,不确定它是否是最好的答案,但它对我有用。我没有使用([name])作为cookie值,而是摆脱了[[])所以我的htaccess看起来像:

RewriteCond %{HTTP_COOKIE} market=dc-metro [NC]
RewriteRule ^fly-a-kite(.*)$ /dc-metro/fly-a-kite$1 [L,R=301]

RewriteCond %{HTTP_COOKIE} market=chicago [NC]
RewriteRule ^fly-a-kite(.*)$ /chicago/fly-a-kite$1 [L,R=301]

#1


I found a solution last night that is working, not sure if it is the best answer, but it is working for me. Instead of using ([name]) for the cookie value I got rid of the ([ ]) so my htaccess looks like:

我昨晚找到了一个有效的解决方案,不确定它是否是最好的答案,但它对我有用。我没有使用([name])作为cookie值,而是摆脱了[[])所以我的htaccess看起来像:

RewriteCond %{HTTP_COOKIE} market=dc-metro [NC]
RewriteRule ^fly-a-kite(.*)$ /dc-metro/fly-a-kite$1 [L,R=301]

RewriteCond %{HTTP_COOKIE} market=chicago [NC]
RewriteRule ^fly-a-kite(.*)$ /chicago/fly-a-kite$1 [L,R=301]