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
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
If you add this above your # Begin WordPress block, it should solve the problem:
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
or
In your case, even after the RewrtieRule the URL appears as
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
WordPress will find your path info (because it tries
$_SERVER['PATH_INFO']
first) so the permalink will bearticles/closeup/childCategory/
Why not use WordPress’s custom taxonomy capability instead? Create a page/post type of “closeup.”