Title: Custom rewrites and querystring issues
Last modified: August 19, 2016

---

# Custom rewrites and querystring issues

 *  [snawbel](https://wordpress.org/support/users/snawbel/)
 * (@snawbel)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/custom-rewrites-and-querystring-issues/)
 * Hi,
 * I’ve run into some problems while trying to organise posts in a slightly unorthodox
   manner.
 * I have one type of url for viewing a selection of posts
 * `/category/thread`
 * where category is, yes, a category of posts. Thread is sort of a context that
   can be a tag, an author or any custom query. Using the following rewrite rule
   I can access the thread variable from the querystring and get the posts for that
   thread in my category.php template file.
 * `'category/([a-z]+)/?$' => 'index.php?category_name=category&thread=$matches[
   1]'`
 * This works nicely! The troubles begin when I try to view a single post in a thread.
   I would like to use the following url
 * `/category/123/thread` (or possibly `/category/thread/123`)
 * where 123 is the ID of a selected post.
 * However, when I try
 * `'category/([0-9]+)/([a-z]+)$' => 'index.php?p=$matches[1]&thread=$matches[2]'`
 * I always end up on `/category/123` and the querystring “thread” variable is not
   accessible. I suspect I’m being redirected by another rule?
 * Any pointers as to how I can arrive at the single post view template with both
   url and querystring intact is greatly appreciated!
 * /Erik
 * PS. I got the url structure right by using category_name instead of p and adding
   another variable to the query string (curr_id) with the selected post ID:
 * `'category/([0-9]+)/([a-z]+)$' => 'index.php?category_name=category&curr_id=$
   matches[1]&thread=$matches[2]'`
 * But then I run into new trouble when using comments, being redirected to `/category/
   123` after submitting the comment. I have a nagging feeling that I’m overcomplicating
   things – that there is a way to do what I want that is more aligned with WordPress
   existing structures.

The topic ‘Custom rewrites and querystring issues’ is closed to new replies.

## Tags

 * [Query String](https://wordpress.org/support/topic-tag/query-string/)
 * [rewrite rules](https://wordpress.org/support/topic-tag/rewrite-rules/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [snawbel](https://wordpress.org/support/users/snawbel/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/custom-rewrites-and-querystring-issues/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
