beginner
beginner

Reputation: 2508

Meaning of ? and $ in htaccess rewrite Rule

I know the basic rewrite rule in .htaccess file. but i can't find the meaning of highlighed ? and $:

RewriteRule ^([a-zA-Z])/?([a-zA-Z])?/?([a-zA-Z0-9]*)?/?$ index.php?controller=$1&action=$2&id=$3 [NC,L]

Formatted rule code:

RewriteRule ^([a-zA-Z]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?$ index.php?controller=$1&action=$2&id=$3 [NC,L]

Can someone tell what they used here. I am trying myself but can't find this anywhere . any help would be very appreciated

Upvotes: 2

Views: 4896

Answers (1)

anubhava
anubhava

Reputation: 785146

This question is more of regex rather than a .htaccess one. Let me try to to answer:

  • ? in regex means 0 or 1 match or to make something an optional match
  • $ is end anchor in regex that means the end of input.

Your rewrite rule appears to be making both action and id components optional and this rule allows for an optional trailing slash at the end of the pretty URI.

Upvotes: 3

Related Questions