Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capture a group in RewriteCond

Tags:

.htaccess

I have this rule:

RewriteCond %{QUERY_STRING} size=(\d+)

and want to capture (\d+) for later use in RewriteRule or RewriteCond. Something like this:

RewriteCond %{QUERY_STRING} size=(\d+)
RewriteCond $1 <1024 ## that $1 refers to (\d+)

How can I achieve that?

like image 308
revo Avatar asked Feb 15 '23 12:02

revo


1 Answers

You need to use the % backreferences:

RewriteCond %{QUERY_STRING} size=(\d+)
RewriteCond ^ /%1 [L]

The %1 backreferences a previously captured group in a rewrite cond.

like image 190
Jon Lin Avatar answered Feb 18 '23 02:02

Jon Lin