【发布时间】: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
第一个在主页上工作,但第二个在类别页面上不工作。
【问题讨论】:
-
如果您不介意不使用 cookie,您可以将城市名称注册到会话中。 w3schools.com/php/php_sessions.asp
标签: php .htaccess mod-rewrite cookies