.htaccess文件_为什么您无法在WordPress网站上找到.htaccess文件

.htaccess文件

Are you having trouble finding the .htaccess file in WordPress? We are often asked by beginners ‘Where is my .htaccess file?’ and ‘Why I cannot find it on my WordPress site?’.

您是否无法在WordPress中找到.htaccess文件? 初学者经常问我们“ .htaccess文件在哪里?” 和“为什么无法在我的WordPress网站上找到它?”。

Sometimes you may need to edit the .htaccess file or delete it to fix a common WordPress errors. In this article, we will explain why you can’t find .htaccess file on your WordPress site, and how to easily locate it.

有时您可能需要编辑.htaccess文件或将其删除以修复常见的WordPress错误 。 在本文中,我们将解释为什么您无法在WordPress网站上找到.htaccess文件,以及如何轻松找到它。

Finding the .htaccess file for your WordPress site
什么是.htaccess文件? (What is .htaccess file?)

The .htaccess file is a server configuration file which tells your server how to handle certain things on your website. Like how to redirect users, password protect admin area, or protect some directories, etc.

.htaccess文件是服务器配置文件,它告诉服务器如何处理网站上的某些内容。 像如何重定向用户一样,用密码保护管理员区保护某些目录等。

It is located in your WordPress site’s root folder. WordPress uses it to manage redirects and permalinks.

它位于您的WordPress网站的根文件夹中。 WordPress使用它来管理重定向和永久链接。

The .htaccess file is an incredibly powerful configuration file and can be used to do a lot useful things. See our article on the most useful .htaccess tricks for WordPress for some examples.

.htaccess文件是一个功能非常强大的配置文件,可以用来做很多有用的事情。 有关某些示例,请参阅我们关于WordPress最有用的.htaccess技巧的文章。

为什么找不到.htaccess文件? (Why I Can’t Find .htaccess File?)

There are two common reasons for not finding the .htaccess file in your website’s root folder. It’s either hidden by your file manager software, or it doesn’t exist at all.

在网站的根文件夹中找不到.htaccess文件的两个常见原因。 它要么被文件管理器软件隐藏,要么根本不存在。

We will explain both of them with solutions.

我们将通过解决方案对它们进行解释。

1.您的FTP客户端未显示隐藏文件 (1. Your FTP Client is Not Showing Hidden Files)

The dot before the htaccess file name indicates that it is a hidden file. By default, when you connect to your WordPress hosting server using an FTP client, it will not show the hidden files.

htaccess文件名前面的点表示它是一个隐藏文件。 默认情况下,当您使用FTP客户端连接到WordPress托管服务器时 ,它不会显示隐藏文件。

To make hidden files visible, you will need to change your FTP client settings.

要使隐藏文件可见,您将需要更改FTP客户端设置。

For example, in FileZilla, you can find the option under ‘Server » Force showing hidden files’ menu.

例如,在FileZilla中,您可以在“服务器»强制显示隐藏文件”菜单下找到该选项。

Show hidden files in FileZilla

If you are using the File Manager app in cPanel, then you will find the option to show hidden files before launching the app.

如果您在cPanel中使用“文件管理器”应用程序,那么您将找到启动该应用程序之前显示隐藏文件的选项。

Show hidden files in cPanel

For other FTP clients, you will find the option to show hidden files in app settings or preferences menu.

对于其他FTP客户端,您会在应用程序设置或首选项菜单中找到显示隐藏文件的选项。

After enabling this option, you would be able to view all hidden files including .htaccess file for your WordPress site.

启用此选项后,您将能够查看WordPress网站的所有隐藏文件,包括.htaccess文件。

2. .htaccess文件不存在 (2. The .htaccess File Doesn’t Exist)

The second most common reason for missing .htaccess file is that your WordPress site has not generated it yet.

丢失.htaccess文件的第二个最常见的原因是您的WordPress网站尚未生成该文件。

WordPress automatically generates .htaccess file because it is required to properly redirect permalinks.

WordPress自动生成.htaccess文件,因为正确重定向永久链接是必需的。

If your .htaccess file is missing, then the first thing you need to do is to visit Settings » Permalinks page and click on ‘Save Changes’ button without changing anything.

如果您的.htaccess文件丢失,那么您要做的第一件事是访问“设置”»“永久链接”页面,然后单击“保存更改”按钮,而不进行任何更改。

Permalinks settings page

WordPress will now try to generate the .htaccess file for you.

WordPress现在将尝试为您生成.htaccess文件。

On some rare occasion, WordPress may not be able to generate the .htaccess file due to file permissions issue.

在极少数情况下,由于文件权限问题,WordPress可能无法生成.htaccess文件。

In that case, it will show you a message at the bottom of the Settings » Permalinks page, saying that the ‘.htaccess file is not writeable’.

在这种情况下,它将在“设置”»“永久链接”页面底部显示一条消息,提示“ .htaccess文件不可写”。

You will need need to manually create the .htaccess file and add the required code inside it.

您将需要手动创建.htaccess文件,并在其中添加所需的代码。

htaccess file not writeable

Simply copy and paste this code in a text editor like Notepad. After that, you need to save it as .htaccess file on your desktop.

只需将此代码复制并粘贴到文本编辑器(如记事本)中。 之后,您需要将其另存为.htaccess文件在桌面上。

Now connect to your website using an FTP client and upload the .htaccess file from your desktop.

现在,使用FTP客户端连接到您的网站,并从桌面上载.htaccess文件。

If you get an error while uploading the file, then you need to change the file permission for your root directory.

如果上传文件时出错,则需要更改根目录的文件许可权

Let’s suppose all your WordPress files reside under /home/johnsmith/public_html/ directory.

假设您所有的WordPress文件都位于/home/johnsmith/public_html/目录下。

This makes public_html folder your root directory. You need to go to its parent directory and right click on the public_html folder. Select File Permissions, which will open a file permissions dialog box.

这使public_html文件夹成为您的根目录。 您需要转到其父目录,然后右键单击public_html文件夹。 选择File Permissions ,这将打开一个文件权限对话框。

Now enter 755 into the file permission dialog box and then try to upload your .htaccess file to the public_html folder.

现在,在文件权限对话框中输入755,然后尝试将您的.htaccess文件上传到public_html文件夹。

Changing file permissions via FTP

We hope this article helped you find .htaccess file on your WordPress site. You may also want to see our WordPress troubleshooting guide to learn how to diagnose and fix WordPress issues all by yourself.

我们希望本文能帮助您在WordPress网站上找到.htaccess文件。 您可能还想查看我们的WordPress故障排除指南,以了解如何自行诊断和修复WordPress问题。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在TwitterFacebook上找到我们。

翻译自: https://www.wpbeginner.com/beginners-guide/why-you-cant-find-htaccess-file-on-your-wordpress-site/

.htaccess文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值