Forum Moderators: phranque

Message Too Old, No Replies

Need help with rewrite rule

cant get this rule to work

         

alexelisenko

1:36 am on Jul 20, 2010 (gmt 0)

10+ Year Member



Hi,

Ive been trying to figure this one out, but cant seem to.

I need to make a rule for rewriting the following url

www.example.com/category-234/section-14-subsection-19

=> example.php?catid=234&section=14&subsection=19

ive had rules work great with either slashes or hyphens, but im not sure how to get both working.

Thanks

jdMorgan

2:07 am on Jul 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure exactly what you're trying to do, since you didn't post the code you've been trying... I'm not sure, therefore, why hyphens and slashes even enter into the problem.

Something like this might help you get started:

RewriteRule ^category-([0-9]+)/section-([0-9]+)-subsection-([0-9]+)$ /example.php?catid=$1&section=$2&subsection=$3 [L]

Jim

g1smd

7:05 am on Jul 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



www.example.com/category-234/-14-subsection-19

Why does the URL have to be that complicated and long?

www.example.com/c234/s14-19
or
www.example.com/234/14-19
would be fine - unless "category" and "section" are the actual names of categories and sections and not the literal words "category" and "section".

If they are the real names of the categories and sections, those words should also be passed as variables to the script and the script should check the right words are being passed to match with the numeric values. If the words don't match the numbers, the PHP script should send a 301 redirect response to the correct URL. This stops Duplicate Content issues appearing on your site.