RewriteRule ^coaching/complete\sin\s\(30\smin,\s1\shour...\)    

http://www.example.com/coaching/complete+in+%2830+min-+1+hour...%29-11

Output Expected

 http://www.example.com/coaching/complete+in+(30+min-+1+hour...)-11

however it is giving output as

http://www.example.com/coaching/complete+in+830+min-+1+hour...9-11

what is the problem in my code?

Comments

Could you please add, what URL do you want to rewrite to what (no regexp, no urlencoding)

Written by inti

That's not a complete rule - you need to show us what it's supposed to look like afterwards. Also, min, != min-, so the rule correctly won't match the URL.

Written by Piskvor

i just breaked the first line so that it is readable i think u get me?

Written by Harish

Accepted Answer

the problem is that %2 is actually interpreted by mod_rewrite as a back-reference to the last matched RewriteCond pattern's second group match.

If there's no such reference, it's simply expanded as an empty string.

So you have first to escape the percent characters like this:

RewriteRule ^coaching/complete\sin\s\(30\smin,\s1\shour...\) http://www.example.com/coaching/complete+in+\%2830+min-+1+hour...\%29-11

However, you also need to use the [NE] flag if you really want those characters to appear as is in the output url, else mod_rewrite will escape them into '(' and ')'.

Written by SirDarius
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki