Simple WordPress RewriteRule

I’m facing a wordpress / htaccess problem. This should be really simple, but it’s not working and I’m getting frustrated.

My site handles permalinks this way: http://www.my-site.com/articles/category/title

Read More

Now, there is a category I called ‘closeup’ for which I don’t want the URL to show ‘article’. So I would like to access content from

http://www.my-site.com/articles/closeup/childCategory/title

with an URL like this

http://www.my-site.com/closeup/childCategory/

I already wrote a page that handles the child category showing all articles on the same page.

So I wrote an htaccess rewrite rule as follows:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^closeup/(.*) articles/closeup/$1 [L]
</IfModule>

I tested the htaccess online on a website which allowed me to test my htaccess rules, and it works fine there, but not on my blog. Any tip?

So the whole htaccess is:

# BEGIN BS

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^closeup/(.*) articles/closeup/$1
</IfModule>

# END BS

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Related posts

Leave a Reply

2 comments

  1. If you add this above your # Begin WordPress block, it should solve the problem:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^closeup/(.*) index.php/articles/closeup/$1 [L]
    </IfModule>
    

    Background:

    ReweriteRule is doing what you expect, it’s WordPress that can’t find the page. To find the post based on the permalink, WordPress uses either

    $_SERVER['PATH_INFO']
    

    or

    $_SERVER['REQUEST_URI']
    

    In your case, even after the RewrtieRule the URL appears as

    http://www.my-site.com/closeup/childCategory/
    

    WordPress uses $_SERVER['REQUEST_URI'] (closeup/childCategory/) to parse the permalink and returns a 404.

    If you use RewriteRule to pass the desired path after index.php

    http://www.my-site.com/index.php?/articles/closeup/childCategory/
    

    WordPress will find your path info (because it tries $_SERVER['PATH_INFO'] first) so the permalink will be articles/closeup/childCategory/