Rewrite rules not working in WordPress

I’m trying to add the new rewrite rules using the rewrite API:

 add_rewrite_rule('product/([A-Z0-9]{10})', 'index.php/product/?asin=$1', 'bottom');
 add_rewrite_rule('product/(([A-Za-z0-9_])*)', 'index.php/product/?product=$1', 'bottom');
 add_rewrite_rule('compare/((([A-Z0-9]{10}),?)*)', 'index.php/compare/?asin=$1', 'bottom');
 add_rewrite_rule('categories/(([A-Za-z0-9]|-|_)*)', 'index.php/categories/?subcategory=$1', 'bottom');

After the permalink is updated it adds the following lines to the .htaccess file:

Read More
RewriteRule ^product/([A-Z0-9]{10}) /index.php/product/?asin=$1 [QSA,L]
RewriteRule ^product/(([A-Za-z0-9_])*) /index.php/product/?product=$1 [QSA,L]
RewriteRule ^compare/((([A-Z0-9]{10}),?)*) /index.php/compare/?asin=$1 [QSA,L]
RewriteRule ^categories/(([A-Za-z0-9]|-|_)*) /index.php/categories/?subcategory=$1 [QSA,L]

resulting to the following .htaccess file:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteRule ^product/([A-Z0-9]{10}) /index.php/product/?asin=$1 [QSA,L]
RewriteRule ^product/(([A-Za-z0-9_])*) /index.php/product/?product=$1 [QSA,L]
RewriteRule ^compare/((([A-Z0-9]{10}),?)*) /index.php/compare/?asin=$1 [QSA,L]
RewriteRule ^categories/(([A-Za-z0-9]|-|_)*) /index.php/categories/?subcategory=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

But when I tried to access the following URL:

http://example.com/product/ABCDE324AB

It doesn’t seem to work. I always get a page not found page. Any ideas?

Related posts

1 comment

  1. What I understand from the above is you have .htaccess file and also correct code written in to the same file but still getting 404 issue. Let me tell you why. Your server not allowing .htaccess file to read or override permission. So how can you give this permission? Open your Apache httpd.conf file serch for AllowOverride now you can see it is present several times. check for below comment in to the same file:

    # AllowOverride controls what directives may be placed in .htaccess files.
        # It can be "All", "None", or any combination of the keywords:
        #   Options FileInfo AuthConfig Limit
        #
        AllowOverride None
    

    Just replace AllowOverride None by AllowOverride All

    Now restart APACHE and it should work

Comments are closed.