Friendly URL with variable parameter

Asked

Viewed 470 times

2

I have the following regular expression for Amicable URL:

RewriteRule ^categoria/([a-z0-9-]+)/([a-z0-9-]+)/([a-z0-9-]+)/?$ categoria.php?idc=$1&nome=$2&pg=$3 [NC]

would like to leave the 3 parameter, pg, optional, have or not have. As I am using it is mandatory to provide the 3 parameter.

  • There are several examples on the site, and more than one with optional parameters, see which one serves best: http://answall.com/search?q=url+amigavel

1 answer

2

Tried that?

RewriteRule ^categoria\/([a-z0-9-]+)\/([a-z0-9-]+)(\/([a-z0-9-]+))?\/?$ categoria.php?idc=$1&nome=$2&pg=$4 [NC]

So you put one group inside the other and make the parent parameter optional by encompassing the bar. In the response variable just skip the parent parameter ($3) until you find the child parameter ($4).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.