.htaccess 文件在 filezilla 中消失?如何检查文件是否存在?
由于某些奇怪的原因,如果地址栏在完整网站名称之前没有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您愿意修改您的index.php,您可以将以下逻辑添加到文件顶部:
If you are willing to modify your index.php you could add the following logic to the top of the file:
在 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'
如果您想使用重写,请确保 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