.htaccess 文件在 filezilla 中消失?如何检查文件是否存在?

发布于 2024-09-13 02:03:15 字数 390 浏览 7 评论 0原文

由于某些奇怪的原因,如果地址栏在完整网站名称之前没有 www,我的 CMS 就会注销。例如,当我们输入 xyz.com 时,它会将我带到该网站,但随后它不会显示为已登录,如果我输入 www.xyz.com,它将找到 cookie 并显示我已登录。

我想要做什么是,当用户输入 xyz.com 时,我希望它直接(对用户透明)转到 www.xyz.com。我想在 xyz.com 之前添加 www。我尝试在index.php所在的目录中添加一个.htaccess文件,这是htaccess文件中的代码。

目录索引index.php
重定向 xyz.com www.xyz.com/index.php

当我通过 ftp filezilla 传输 .htaccess 文件时,该文件消失了。

for some weird reason my CMS is logging out if the address bar does not have www before the full website name. for example, when we enter xyz.com, it takes me to the website but then it wont show as logged in and if i type in www.xyz.com it will find the cookie and show me logged in.

What i want to do is, when user types in xyz.com, i want it to directly (transparent to user) go to www.xyz.com. I want to add that www before xyz.com. I tried adding a .htaccess file in the directory where index.php is present and this is code in htaccess file.

DirectoryIndex index.php
Redirect xyz.com www.xyz.com/index.php

The .htaccess file is disappearing when i transfer it over ftp filezilla.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

余罪 2024-09-20 02:03:15

如果您愿意修改您的index.php,您可以将以下逻辑添加到文件顶部:

/*This is a tempory redirection from mysite.com to www.mysite.com*/
if($_SERVER['SERVER_NAME'] == 'mysite.com')
{
    $redirect =     $_SERVER['REQUEST_URI'];
    header( 'Location: http://www.mysite.com'. $redirect ) ;
}

If you are willing to modify your index.php you could add the following logic to the top of the file:

/*This is a tempory redirection from mysite.com to www.mysite.com*/
if($_SERVER['SERVER_NAME'] == 'mysite.com')
{
    $redirect =     $_SERVER['REQUEST_URI'];
    header( 'Location: http://www.mysite.com'. $redirect ) ;
}
如何视而不见 2024-09-20 02:03:15

在 htaccess 文件中尝试一下:

选项 +FollowSymlinks
RewriteEngine 开启
RewriteCond %{HTTP_HOST} ^xyz.com$
RewriteRule ^/?$ "http://www.xyz.com" [R=301,L]

但是,您的问题听起来像是与 cookie 有关。可能 CMS 使用 cookie 来检查登录状态,但 cookie 域参数是“www.xyz.com”而不是“.xyz.com”。

--- 编辑 ---

改进了代码的最后一行(它已经过测试并且可以工作),但正如 tcp 所说,必须启用 mod_rewrite。如果您无法启用它,请尝试 Lobsterm 发布的代码,如果您也无法执行此操作,您可以尝试将 cookie 域参数从“www.xyz.com”更改为“.xyz.com”

try this in the htaccess file:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^xyz.com$
RewriteRule ^/?$ "http://www.xyz.com" [R=301,L]

However, your problem sounds like cookie related. Probably the CMS is using a cookie to check the log in status, but the cookie domain param is 'www.xyz.com' instead of '.xyz.com'.

--- edit ---

improved a bit the final line of the code (it is tested and working), but as tcp said, mod_rewrite must be enabled. If you can't enable it, try the code that Lobsterm posted and if you can't do this either, you could try to change the cookie domain param from 'www.xyz.com' to '.xyz.com'

枕头说它不想醒 2024-09-20 02:03:15

如果您想使用重写,请确保 mod_rewrite 已加载到您的 Apache conf 文件中,并检查 AllowOverride 参数是否设置为 All 或仅设置您希望在 .htaccess 中允许的指令

另外,正如 aletzo 所说,您可能想要您的 cookie 覆盖您的整个域,因此将 cookie 域从 www.example.com 更改为 example.com 。
然后,用户是否使用 www 前缀或在子域内访问都没有关系。

编辑:很高兴您找到了您正在寻找的答案,但是如果您将来需要让 filezilla 向您显示 .htaccess,服务器 ->强制显示隐藏文件

If you want to use rewrites, make sure mod_rewrite is being loaded in your Apache conf file and check that the AllowOverride parameter is either set to All or the just the directives you want to be allowed in .htaccess

Also as aletzo said, you probably want your cookie to cover your whole domain so change the cookie domain from www.example.com to example.com .
Then, it won't matter if user are accessing with a www prefix or within a subdomain.

EDIT: Glad you found the answer you were looking for, but if you need to make filezilla show you .htaccess in the future, Server -> Force showing hidden files

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文