Reputation: 7906
I am stuck in some URL rewriting problem.
RewriteRule ^(userratings)/(.*)$ /user_rating.php?userId=$2 [L]
This is working for me.
i want to add 3rd variable also. But it might be there or not there also.
RewriteRule ^(userratings)/(.*)/(.*)$ /abc.php?userId=$2&product=$3 [L]
but the last /(.*)
can be there or not be there also . So how do i write it for such a condition?
Upvotes: 1
Views: 57
Reputation: 165463
This rule will do the job:
RewriteRule ^userratings/([^/]+)(/(.*))?$ /abc.php?userId=$1&product=$3 [QSA,L]
Test Examples:
/userratings/12345/hello
will be rewritten into /abc.php?userId=12345&product=hello
/userratings/12345
will be rewritten into /abc.php?userId=12345&product=
This means, that if 3rd parameter in URL path is not present, then value of product=
will be empty string.
Upvotes: 2