htaccess 文件有问题。 WordPress 插件告诉我有一个,我找不到?

发布于 2024-09-10 07:01:21 字数 528 浏览 3 评论 0原文

我有一个非常不寻常的问题,我以前从未遇到过。 我的服务器上没有 .htaccess 文件。到处查看,都没有文件,但是 Wordpress 插件 (AskApacheRewriteRules) 告诉我以下规则处于活动状态:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

知道为什么会这样,我已经编写了我的托管提供商,但他们的服务不是最好的。

即使我使用其他规则创建 htaccess 文件并将其保存到服务器的根目录中,它也不会改变任何内容。该插件总是告诉我相同的信息,并且我相信该插件,因为我的网址中的 /index.php/ 有问题(我不想有)。

有什么想法吗?

i have an really unusual problem i've never had before.
i've no .htaccess file on my server. looked everywhere, there is just no file, but a Wordpress Plugin (AskApacheRewriteRules) tells me that the following Rules are active:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

any idea why that could be, i've already wrote my hosting provider, but their service isn't the best.

even if i create an htaccess file with other rules and save it to my root of the server, it doesn't change anything. The plugin always tells me the same and i believe the plugin, because i'm having issues with the /index.php/ in my url (that i don't want to have).

any ideas?

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

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

发布评论

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

评论(2

甜嗑 2024-09-17 07:01:21

在 AskApacheRewriteRules 选项页面上,您是否确保将 using_index_permalinks 设置为 false 并将 using_mod_rewrite_permalinks 设置为 true >?如果不是这种情况,WordPress 将尝试使用 PATH_INFO 作为您的永久链接,从而生成 /index.php/(permalink_struct)

请注意,WordPress 重写类将其重写规则作为 WordPress 选项存储在数据库中,这是 AskApacheRewriteRules 获取其信息的地方。该插件显然还使用 mod_rewrite_rules 函数格式化规则,然后将它们回显到页面,页面将围绕它们:

<IfModule mod_rewrite.c>
...
</IfModule>

所以,您找不到 .htaccess 文件是因为它不存在;规则仅存在于数据库中。这些规则出现在数据库中的原因是因为您使用的是永久链接,这是自动生成的 WordPress 规则集,无论是否实际使用它都会保存。

编辑:您的 Web 目录根目录中必须有一个 .htaccess 文件,其中包含以下内容:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If mod_rewrite isn't available, we'll do this a hackish (and bad) way...
    ErrorDocument 404 /index.php
</IfModule>

rewrite_rules 选项存储在 SELECT option_value FROM wp_options WHERE option_name = 'rewrite_rules' 中,但每次更改永久链接时都会重新生成,并且除了写入 .htaccess 时不会使用该选项代码> 据我所知。

无论如何,这些绝对是您想做的事情的正确规则。您确定您的主机启用了 mod_rewrite 吗?

编辑:

让我们 100% 确保 mod_rewrite 正常工作,然后从那里开始。

按照以下规则在您的 Web 根目录中创建一个 .htaccess 文件:

RewriteEngine On
RewriteRule ^rwtest http://stackoverflow.com/ [R,L]

然后使用 URL example.com/rwtest 访问您的网站,看看是否获得重定向到 StackOverflow。如果不是,则 mod_rewrite 有问题。如果你这样做了,那么至少我们知道那部分不是问题。

On the AskApacheRewriteRules options page, did you make sure that using_index_permalinks is set to false and that using_mod_rewrite_permalinks is set to true? If this isn't the case, WordPress will attempt to use PATH_INFO for your permalinks, resulting in /index.php/(permalink_structure).

Note that the WordPress rewrite class stores its rewrite rules as a WordPress option in the database, which is where AskApacheRewriteRules gets its information. The plugin also apparently formats the rules with the mod_rewrite_rules function before echoing them to the page, which will surround them with:

<IfModule mod_rewrite.c>
...
</IfModule>

So, the likely reason you can't find the .htaccess file is because it doesn't exist; the rules are just present in the database. The reason why the rules are present in the database is because you're using permalinks, and this is the auto-generated WordPress ruleset, which is saved regardless of whether it's actually being used or not.

Edit: You must have a .htaccess file in the root of your web directory with the following contents:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If mod_rewrite isn't available, we'll do this a hackish (and bad) way...
    ErrorDocument 404 /index.php
</IfModule>

The rewrite_rules option is stored at SELECT option_value FROM wp_options WHERE option_name = 'rewrite_rules', but it gets regenerated every time you change the permalink, and isn't used except for writing to .htaccess from what I can tell.

Anyway, those are definitely the correct rules for what you want to do. Are you sure that mod_rewrite is enabled on your host?

Edit:

Let's make 100% sure that mod_rewrite is working correctly and go from there.

Create a .htaccess file in your web root with the following rules, exactly as written:

RewriteEngine On
RewriteRule ^rwtest http://stackoverflow.com/ [R,L]

Then go to your site with the URL example.com/rwtest and see if you get redirected to StackOverflow. If not, something is wrong with mod_rewrite. If you do, then at least we know that piece isn't the problem.

你的呼吸 2024-09-17 07:01:21

您是否检查过它是否在您的 apache 配置文件中定义了(该插件似乎显示了其中的摘录)。

Have you checked if it's defined in your apache configuration file (it appears that the plug is showing an excerpt from that).

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