htaccess wordpress rewriterule无效404错误

时间:2018-01-09 09:35:32

标签: wordpress .htaccess mod-rewrite

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

<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>

当我输入我的网址时,它显示404错误,但“index.php / file /?value = $ 1”对我来说工作正常。

任何帮助?

编辑:

仍然没有工作......我已经处理了这个问题差不多一个星期所以如果有人知道如何做这个工作请告诉我。

编辑2 [解决方案]:

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

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文件,如:

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

希望这可以帮助某人!

1 个答案:

答案 0 :(得分:1)

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

FallbackResource /index.php

这消除了重写的复杂性和脆弱性,并且更有效。