Rahul
Rahul

Reputation: 2279

.htaccess redirection not working perhaps missing regular expression

I am using the following regular expression in .htaccess file

RewriteRule ^js_embed/([a-zA-Z0-9\-_]+)/[0-9]+ /users/$1/js_embed_$2.html [R=301,L]

basically what I am trying is to do is, redirect

/js_embed/platform/37482 to /users/$1/js_embed_$2.html

however I am getting blank $2 value, I mean I am expecting $2=37482

I am missing something in my regular expression?

Upvotes: 0

Views: 92

Answers (3)

Andrew White
Andrew White

Reputation: 53516

You don't have a second capture group. Perhaps you mean...

RewriteRule ^js_embed/([a-zA-Z0-9\-_]+)/([0-9]+) /users/$1/js_embed_$2.html [R=301,L]

Upvotes: 0

Prashant Bhate
Prashant Bhate

Reputation: 11087

Are you missing braces around [0-9]+ ?

RewriteRule ^js_embed/([a-zA-Z0-9\-_]+)/([0-9]+) /users/$1/js_embed_$2.html [R=301,L]

Upvotes: 1

Ulrich Palha
Ulrich Palha

Reputation: 9539

You are missing a parentheses around the second capture expression

RewriteRule ^js_embed/([a-zA-Z0-9\-_]+)/([0-9]+) /users/$1/js_embed_$2.html [R=301,L]

Upvotes: 0

Related Questions