htaccess wordpress rewriterule not working 404 error

霸气de小男生 提交于 2021-01-28 04:51:28

问题


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>

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

Any help?

EDIT:

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.

EDIT 2 [SOLUTION]:

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');

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>

Hope this could help somebody!


回答1:


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.



来源:https://stackoverflow.com/questions/48165120/htaccess-wordpress-rewriterule-not-working-404-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!