Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6063599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:11:02+00:00 2026-05-23T09:11:02+00:00

I have a fairly complex content management system I’ve written in PHP, which has

  • 0

I have a fairly complex content management system I’ve written in PHP, which has unlimited hierarchical categories.

Each category has a shortname (dynamically generated from the category title) which I using with mod_rewrite to produce clean URLs, for example

http://www.mysite.com/categories/january

The problem with this approach is that each category requires a unique shortname for it to work properly. This creates a problem when I have more than one category with the same name, with different categories, e.g. /categories/2011/january and /categories/2010/january.

The easiest way to overcome this is to append -1, -2 etc when a duplicate shortname is created, but I would much prefer to have the whole category hierarchy used in the URL and determine the right Ids based on this, e.g.

http://www.mysite.com/categories/2011/january vs
http://www.mysite.com/categories/2010/january

My question is this: Is there a way that I can use mod_rewrite to parse any number of subcategories, and return these to my php page, perhaps as an array of values?

It would need to work regardless of the number of subcategories, so it could process e.g.

http://www.mysite.com/categories/products/sheds/reports/2011/january

with the same code, and give my php page an array of those categories in the order they are shown in the URL?

My code would then need to work backwards from the last category to figure out which category is required based upon it’s parents.

Is this something that would be feasible (and indeed recommended), and could anyone give me a hand with producing the correct regular expression for the rewrite command, given my pretty hopeless grasp of regex?

Many thanks in advance
Nick

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:11:03+00:00Added an answer on May 23, 2026 at 9:11 am

    I don’t think there is any easy way to let mod_rewrite split the data for you. Of course, you could build a RewriteRule that matches up to 9 virtual paths, but I don’t think that this would be helpful. Instead I would suggest to define a rule like this

    RewriteRule ^categories/(.*)$ category-handler.php?cat=$1
    

    and then do the splitting (and re-ordering) in the PHP file, something like this

    $cat = $_GET['cat'];
    $splittedCat = array_reverse(preg_split('/\//', $cat));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our users have created MS-Excel spreadsheets which over time have evolved into fairly complex
I have some fairly complex libraries that interconnect with each other to do some
I have a fairly complex OLAP database, which basically amounts to a header record,
For those of you who have written fairly complex PyQt applications, what tips and
I have a fairly complex CLR stored procedure. What is the best way to
I have a fat GUI that it getting fairly complex, and I would like
We have fairly large C++ application which is composed of about 60 projects in
I have an odd question, and seeing as the real context is fairly complex
I have a fairly complex procedure that currently takes about 1:30 (min:sec) to complete.
I have a fairly complex problem. I have read some similar posts to my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.