Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 262
molinet Avatar asked Dec 05 '25 18:12

molinet


1 Answers

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.

like image 178
Rich Bowen Avatar answered Dec 08 '25 18:12

Rich Bowen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!