vendredi 3 mai 2019

htaccess show category, sub category and post in url

I'm currently building out a simple site but struggling with a bit of htaccess.

I want my links such as services, about, blog etc to be categories.

I then want to have sub categories from then such as ppc for services, meet the team for about and a selection of blog posts for blog.

When you click on the link such as a post within ppc you get the following URL structure:

sitename/category-name/subcategory-name/post-name

sitename/services/ppc/ppc-management

So far I have been able to get the url to show like this:

sitename/category-name/subcategory-name

or

sitename/category-name/post-name

As you can see when i get to post-name it removes the subcategory-name from the url. I have also forced it to show services before the category-name.

My current htaccess file looks like this:

RewriteEngine On
RewriteBase /

RewriteRule ^services/(.*)$ catpost.php?id=$1 [L]
RewriteRule ^a-(.*)-(.*)$ archives.php?month=$1&year=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ viewpost.php?id=$1 [QSA,L]

I'm struggling with fixing these two issues:

1) Having a dynamic url insertion before the catpost.php

  • If i have a services.php which pulls in everything from that category i'd like to have services inserted before the slash. So that could change to about or blog etc depending on the page.

2) Keeping the subcategory-name in the url when you view the post

Any help is greatly appreciate. I hope this post is clear but if it isn't please let me know so I can improve.




Aucun commentaire:

Enregistrer un commentaire