【问题标题】:PHP Cookie not available if i'm using .htaccess mod rewrite rule如果我使用 .htaccess mod 重写规则,PHP Cookie 不可用
【发布时间】:2017-12-23 14:57:10
【问题描述】:

我正在使用 .htaccess 重写规则。 我的规则是

Options -MultiViews

RewriteEngine on
RewriteRule ^Login login.php [NC,L]
RewriteRule ^Register register.php [NC,L]
RewriteRule ^Posts/([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+) posts.php?category=$1&subcategory=$2 [NC,L]

一切正常,但问题出在这里:

如果我访问

<a href='Login'>Login</a> from website home page it is redirecting to login.php that is perfectly working

但如果我访问

<a href='Login'>Login</a> from website posts page it is redirecting to Posts/login.php which is incorrect. It should redirect to login.php only.

为了解决这个问题,我在登录按钮中使用了直接页面

<a href='http://www.mywebsite.com/Login'>Login</a> 

它工作得很好,但问题是,cookie 不可用,因为我需要在每个页面的 cookie 中维护城市名称。

检查我的网站链接: http://fidfeet.com/Login, http://fidfeet.com/Categories/Login

第一个在主页上工作,但第二个在类别页面上不工作。

【问题讨论】:

标签: php .htaccess mod-rewrite cookies


【解决方案1】:

您的链接指向相对路径,这就是为什么它们没有从子目录解析到同一个位置的原因。它们应该指向 /Login 以引用根目录下的登录。

在从第一个路径定义 cookie 后,该 cookie 在第二个路径中可用。右上角有一个框,列出了我选择的城市。

【讨论】:

    猜你喜欢
    • 2015-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多