.htaccess - htaccess from www to non-www bringing variable in session/cookie -
.htacces redirects www.example.com
example.com
(same domain without www.)
returning visitor have in user-agent visitor_id
cookie.
want bring value through domains within cookie or session.
tried this, cookie created www domain
rewritecond %{http_host} ^www.example.com rewritecond %{http_cookie} visitor_id=([^;]+) rewriterule .* - [c,env=foo:%1] rewriterule ^(.*) http://example.com [l,r=301] header set set-cookie "visitor_id=%{foo}e; path=/" env=foo
moreover environment variable works on localhost (apache 2.4.2, win32), online (apache 2.2.25, linux) value in cookie "%{foo}e"
instead of expected number.
also tried mod_session_cookie
can't find practical examples.
how redirect through domains, bringing visitor_id
in cookie or session cookie?
since, environment %{env}
variables not behaving consistently across different apache versions, suggest setting cookie rewriterule
using [co]
cookie flag.
rewritecond %{http_host} ^www\.example\.com$ [nc] rewritecond %{http_cookie} visitor_id=([^;]+) [nc] rewriterule .* $0/vid/%1 [c] # appends cookie value url rewriterule ^(.*)/vid/(.*)$ http://example.com/$1 [l,r=301,co=visitor_id:$2:.example.com:14400:/]
here list of changes made .htaccess
file:
rewritecond
matches case-insensitive (using[nc]
)the dots in
%{http_host}
condition have been escaped\.
(.
matches char otherwise)the first
rewriterule
appends visitor id (captured%1
) url (captured$0
)the last
rewriterule
parses visitor id url (as$1
) , performs permanent[r=301]
redirecthttp://example.com
along writing cookie namedvisitor_id
using[co]
flag.
the syntax of cookie rewrite flag follows
[co=name:value:domain:lifetime:path:secure:httponly]
where specifying values name, value , domain mandatory. lifetime defaults 0
means cookie persists current browser session only. path defaults /
, secure , httponly false
.
the [co]
flag used specifies domain .example.com
cookie becomes accessible hosts under example.com
domain. lifetime specified 14400
in minutes , amounts 10
days.
Comments
Post a Comment