0

I'm attempting to setup a custom URL structure within posts that makes all parents and sub child's accessible, but all attempts have failed with various errors.

My category structure looks something like this:

  1. - Cars
  2. -- Mondeo
  3. --- 1994
  4. ---- Postname

The idea is that people can access the following pages:

  • example.com/cars/
  • example.com/cars/mondeo/
  • example.com/cars/mondeo/1994/
  • example.com/cars/mondeo/1994/postname/

Postname (the article will be added to all categories listed above and the primary will be set to the last sub catagory listed).

What I've tried:

  • Setting permalinks to /%category%/%postname%/ this results in 404's when attempting to visit /cars/mondeo/ or /cars/mondeo/1994/. This however works when visiting /cars/ and /cars/mondeo/1994/postname/.
  • Using /%category%/%subcategory%/%postname%/ as the permalinks makes the sub categories work, but then breaks the parents and the postnames... not good.

.htaccess / mod_rewrite is enabled and working:

I have tested the .htaccess adding a deny, i.e:

# Test HTACCESS
Deny from all 

# 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 Word

I hate the .php method, surely there is a better way...

The only solutions I've been able to find on here are by using a dirty .php method, which seems silly, I cant believe that WordPress can't handle this and I imagine that this has been asked in various forms and I've not found them, in which case please kindly point me in the right direction.

2
  • Basically, you have a situation where multiple types of things match the same rewrite pattern. WordPress has to know if you're asking for a post or a category before it goes and queries for it. That's why the .php method works, it adds a unique element to the pattern that will only match posts. Have a look at this question which is a similar issue, you have to do a bit of work yourself to help WordPress know what you're asking for.
    – Milo
    Commented May 15, 2016 at 2:47
  • Hey @Milo, oh right, can this be done just in the .htaccess or does it require a bit of both? I've looked at the post and I kinda understand it to some degree, that WordPress needs to be told what it is. Commented May 15, 2016 at 9:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.