当你在谷歌上搜索这个问题时,人们可以找到很多模拟问题,但没有一个单一的解决方案。
我有这个网站:
www.website.com
我的 CakePhp 3.x 项目位于此目录中
www.website.com/project
会话在以前的项目中使用,因此我必须在应用程序中自定义会话.php才能访问它们
'Session' => [
'defaults' => 'php',
'cookie' => 'PHPSESSID',
'timeout' => '20000',
'ini' => [
'session.cookie_domain' => '.website.com',
'session.save_path' => '/var/www/clients/client1/web/tmp/',
]
],
!!一切都很好 浏览 http://www.website.com/project 它保持会话完整!!
在htaccess中,我使/project文件夹不可见,因此:
http://www.website.com/project becomes http://www.website.com/
http://www.website.com/project/start becomes http://www.website.com/start
...
现在;http://www.website.com/和 http://www.website.com/start 正在失去我的会话
这是我的htaccess文件:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !website.com$ [NC]
RewriteRule ^(.*)$ http://www.website.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^website.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.website.com$
RewriteCond %{HTTP_HOST} !^www.website.com$
RewriteRule (.*) http://www.website.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
#rewrite previous project to root
RewriteRule ^/?$ "http://www.website.com/sys" [R=301,L]
#do nothing with these urls
RewriteCond %{REQUEST_URI} !^/portret/.*$
RewriteCond %{REQUEST_URI} !^/temp/.*$
RewriteCond %{REQUEST_URI} !^/tempcs/.*$
RewriteCond %{REQUEST_URI} !^/tempmail/.*$
RewriteCond %{REQUEST_URI} !^/tempsoc/.*$
RewriteCond %{REQUEST_URI} !^/tempzip/.*$
RewriteCond %{REQUEST_URI} !^/web/.*$
#disable project folder to make it nice
RewriteRule (.*) /project/$1 [QSA,L]
#fixing some pains-in-the-ass
Redirect 301 /FDM http://old-website/web/index1.php?ID=FDM
Redirect 301 /GM http://old-website.be/web/index1.php?ID=GM
Redirect 301 /FC http://old-website.be/web/index1.php?ID=FC
#set the root
DirectoryIndex project/search/start
一些调试信息:
session_get_cookie_params
Array ( [lifetime] => 0 [path] => /project/ [domain] => .website.com [secure] => [httponly] => 1 )
CakePhp Debugkit Cookie 请求在没有/project 的页面上
__unameb00ce0-152452f3c4a-10c277e4-12
PHPSESSID j1guvr5armlfpa7aa64aa9lfe1
_gaGA1.2.1776275125.1452677383
_gat1
CakePhp Debugkit Cookie 请求在带有/project 的页面上
search Q2FrZQ==.MWQ3MzRhMWY3YWVmMzY0OGEzN2QwODFjMmY0MDE3NTdiOTI4OTQ5NDYxNmNhNmYwNzMyMjRmOTExNDA5NDJlOR+xldRH1lAaIbKGzowwWjtleNpkY/NYKZjft08u3Q8C
PHPSESSID 3amnr19lag1l0s7v5f20us4rq7
language Q2FrZQ==.ZDdjOWQ2NmI2ZDhiNWYzZGM2Zjg4MjRkM2NjMzRjMGRiMmM3NzM4MmEzMzRmZTFkNDI2NDhkY2U4MjBhOGZjM/ARPIqb98q5NwFN9JLi/HelqGCM6V3bsdCFlxxOkI/z
__unameb00ce0-152452f3c4a-10c277e4-12
_gat1
_gaGA1.2.1776275125.1452677383
以下设置对我有用:
'Session' => [
'defaults' => 'php',
'ini' => [
'session.cookie_path' => '/'
]
],