【问题标题】:cakephp 3.x and htaccess mod_rewrite make my sessions disappearcakephp 3.x 和 htaccess mod_rewrite 让我的会话消失
【发布时间】:2016-04-27 12:33:01
【问题描述】:

当你用谷歌搜索这个问题时,你会发现很多类似的问题,但没有单一的解决方案。

我有这个网站:

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 中,我使 /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 )

没有 /project 的页面上的 CakePhp Debugkit Cookie 请求

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

带有 /project 的页面上的 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

【问题讨论】:

  • 能否在您的问题中添加“session_get_cookie_params”的结果?
  • 我添加了一些更多的调试信息,你可以清楚地看到它创建了一个新的会话 ID
  • 为什么session_get_cookie_params路径是/project/?你确定“/var/www/clients/client1/web/tmp/”存在吗?

标签: apache .htaccess cakephp mod-rewrite cakephp-3.0


【解决方案1】:

以下设置对我有用:

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

【讨论】:

    猜你喜欢
    • 2011-05-04
    • 1970-01-01
    • 2015-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多