2016-01-21 16 views
1

当你对这个问题的谷歌,可以发现很多类似的问题,但没有单一的解决方案。cakephp 3.x和htaccess mod_rewrite让我的会话消失

我有这个网站:

www.website.com 

我的CakePHP 3.x的项目位于该目录

www.website.com/project 

会议在以前的项目中使用的,所以我要定制会话在app.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的我做出/项目文件夹无形这样:

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的请求/项目

__unameb00ce0-152452f3c4a-10c277e4-12 
PHPSESSID j1guvr5armlfpa7aa64aa9lfe1 
_gaGA1.2.1776275125.1452677383 
_gat1 

与网页上的CakePHP Debugkit Cookie的请求/项目

search Q2FrZQ==.MWQ3MzRhMWY3YWVmMzY0OGEzN2QwODFjMmY0MDE3NTdiOTI4OTQ5NDYxNmNhNmYwNzMyMjRmOTExNDA5NDJlOR+xldRH1lAaIbKGzowwWjtleNpkY/NYKZjft08u3Q8C 
PHPSESSID 3amnr19lag1l0s7v5f20us4rq7 
language Q2FrZQ==.ZDdjOWQ2NmI2ZDhiNWYzZGM2Zjg4MjRkM2NjMzRjMGRiMmM3NzM4MmEzMzRmZTFkNDI2NDhkY2U4MjBhOGZjM/ARPIqb98q5NwFN9JLi/HelqGCM6V3bsdCFlxxOkI/z 
__unameb00ce0-152452f3c4a-10c277e4-12 
_gat1 
_gaGA1.2.1776275125.1452677383 
+0

你可以在你的问题中添加“session_get_cookie_params”的结果吗? – DIDoS

+0

我添加了一些更多的调试信息,您可以清楚地看到它创建了一个新的会话ID – Joost

+0

为什么session_get_cookie_params路径/ project /?你确定“/ var/www/clients/client1/web/tmp /”存在吗? – DIDoS

回答

0

以下设置为我工作:

'Session' => [ 
     'defaults' => 'php', 
     'ini' => [ 
      'session.cookie_path' => '/' 
     ] 
    ],