htaccess wordpress rewriterule 不工作 404 错误 [英] htaccess wordpress rewriterule not working 404 error

查看:61
本文介绍了htaccess wordpress rewriterule 不工作 404 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为一个页面重新编写一个页面,以加载另一个页面的内容并显示正确的信息.

I'm attempting to make a rewriterule for a page to load the content of another one and show the proper information.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index\.php/file/(.*)$ index.php/file/?value=$1 [L,QSA]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

当我输入 url 时,它显示 404 错误,但index.php/file/?value=$1"对我来说工作正常.

When i put my url it shows me a 404 error but the "index.php/file/?value=$1" is working fine for me.

有什么帮助吗?

仍然无法正常工作...我已经处理这个问题将近一个星期了,所以如果有人知道如何解决这个问题,请告诉我.

Still not working... I've been dealing with this issue for almost a week so if someone knows how to make this work please tell me.

编辑 2 [解决方案]:

我终于解决了我的问题.关键是我需要从 wp 主题对我的 functions.php 文件进行一些更改:

I finally get to solve my problem. The point is that I needed to make some changes into my functions.php file from the wp theme:

add_filter('query_vars', 'add_state_var', 0, 1);
function add_state_var($vars){
    $vars[] = 'value';
    return $vars;
}

add_rewrite_rule('^file/([^/]+)/?$','index.php?
pagename=file&value=$matches[1]','top');

并保留我的 .htaccess 文件,例如:

and leave my .htaccess file like:

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

希望这可以帮助某人!

推荐答案

我们还建议您删除整个 RewriteRule 块并将其替换为一行:

We also recommend that you drop that entire RewriteRule block and replace it with the one line:

FallbackResource /index.php

这消除了重写的复杂性和脆弱性,并且效率更高.

This eliminates the complexity and fragility of the rewrites and is more efficient.

这篇关于htaccess wordpress rewriterule 不工作 404 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆