Jump to content

Can't get mod_rewrite url to work correctly


Jason28

Recommended Posts

I tried different only tools and tutorials about mod_rewrite but I cannot find what I am looking for.  I want to rewrite a url like this (I wont include site domain since it is all within the same site directory):

 

/area-1/(random text here)/category-5/(random text here)/

 

I only want it to find the area number within the slashes /area-ID/ and the category within the slashes /category-ID/ and ignore all of the other text since it changes based on the page title.  I tried:

 

RewriteRule ^area-([-0-9]+)/([^/]*)/category-([-0-9]+)\/    test.php?id=$1&var=$2&cat_id=$3 [L]

 

The $var=2 is empty and not needed, but needed to add something there to ignore the stuff in the middle.  Please help, I cannot create an account at Stackoverflow because the signup always errors.  I contacted their webmaster with no reply.  Thanks.

Try this rule

RewriteRule ^area-([0-9]+)/[^/]+/category-([0-9]+)/    test.php?id=$1&cat_id=$2 [L]

 

The $var=2 is empty and not needed, but needed to add something there to ignore the stuff in the middle.

Then don't wrap parentheses around regex that you dont want to reference later on.

 

 

I cannot create an account at Stackoverflow because the signup always errors.

Not relevant  :tease-01:

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.