6

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:

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?

  • is it a wordpress or server 404 page? – Mark Kaplun Nov 25 '13 at 11:10
  • Once you have made any changes, don't forget to goto Settings > Permalinks and click Save to flush the rewrite rules. – TomC Nov 25 '13 at 12:10
  • yeah I've already flushed the rewrite rules by using the 'post name' permalink and then saving it but still doesn't work. – soul Nov 25 '13 at 23:44
7

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

  • This can also help you: httpd.apache.org/docs/current/mod/core.html#allowoverride – Manish Nov 25 '13 at 12:04
  • 1
    it seems like the override is actually working because when I referenced a file that's outside of wordpress it was actually able to follow the rewrite rules. I just don't know why it wouldn't work with wordpress pages. – soul Nov 26 '13 at 7:43
  • ok so do one thing. have backup of your htacces file and remove all code and add default htaccess code to this file. then go to permalink page and select default permalink. after that access the site I am sure site will work. Then try with other permalink setup. – Manish Nov 26 '13 at 17:05
  • this doesn't work either – soul Dec 18 '13 at 3:12
  • You mean, you are not able to access the site with default permalink? – Manish Dec 18 '13 at 5:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.