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.

Link to comment
Share on other sites

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:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.