molinet
molinet

Reputation: 276

htaccess wordpress rewriterule not working 404 error

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!

Upvotes: 3

Views: 1094

Answers (1)

Rich Bowen
Rich Bowen

Reputation: 5892

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.

Upvotes: 2

Related Questions