user2004478
user2004478

Reputation: 91

Trouble rewriting my htaccess

FOLLOWUP QUESTION ADDED TO THE BOTTOM!

I'm running a bunch of php code on my index page to check for GET values, but I'm having trouble figuring out how to rewrite the URLs.

I want to rewrite my URL form this: www.domain.com?topic=courses&title=coursetitle&chapter=chaptertitle Well, I guess technically it looks like this, right?: www.domain.com/index.php?topic=courses&title=coursetitle&chapter=chaptertitle

to this: www.domain.com/courses/coursetitle/chaptertitle

In other words, I have multiple GET values, and I want each to be displayed after a slash, but not have index.php displayed at all. Does that make sense? I'm sory if I'm bad at explaining it.

Also, if you got the time to explain what each part of the code does, so I don't just end up copy pasting it, but actually learn what's going on, that would be appriciated.


Followup question

I have 4 different topics on my webpage, lets use colors as example names (red, blue, green, yellow).

Topic "red" has an subcategory, lets say this is called "hue", and "hue" itself has a subcategory of "saturation".

Lets give "hue" a value of 8, and "saturation" a value of 3. Now the URL should look something like this: www.domain.com/red/8/3

Rewritten from: www.domain.com/index.php?topic=red&hue=8&saturation=3

This is all fine and dandy, and the code you provided in the comments does that for me.

Now, lets give our "blue" topic some subcategories as well. Lets says "darkness" with a value of 2, and keep it at one subcategory for simplicity

Now, if I go to: www.domain.com/blue/2

How do I make sure it knows that my second GET value is supposed to be $_GET['darkness'], and not $_GET['hue'] like my first rewrite tells it to be?

Is there a way to look at my first GET value, and from that decide if the next value it reads is one or the other?

Or am I best of making real pages for my 4 subjects, instead of running everything from my index, and then create rewrites for each?

Upvotes: 0

Views: 30

Answers (1)

Adrianopolis
Adrianopolis

Reputation: 1292

This should do the trick for you:

RewriteEngine On 
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /index.php?topic=$1&title=$2&chapter=$3 [L]

Upvotes: 1

Related Questions