Reputation: 47
I need to put some numbers into a resulting url in urlrewrite rule, so from url like "/test/723/" I'll get "/test/700-series/723/" Obviously this
RewriteRule ^/test/([1-9])([0-9]{2})/$ /test/$100-series/$1$2/
doesn't work because of $100 can't be interpreted correctly. Is there any way to separate $1 from any numbers behind it?
Upvotes: 3
Views: 247
Reputation: 784898
You're pretty close, just remove the leading slash:
RewriteRule ^test/([1-9])([0-9]{2})/?$ /test/$100-series/$1$2/ [L]
.htaccess
is per directory directive and Apache strips the current directory path (thus leading slash) from RewriteRule
URI pattern.As per official Apache doc It clearly states that:
RewriteRule backreferences: These are backreferences of the form $N (0 <= N <= 9). $1 to $9 provide access to the grouped parts (in parentheses) of the pattern, from the RewriteRule which is subject to the current set of RewriteCond conditions. $0 provides access to the whole string matched by that pattern.
Hence $100 is always interpreted as $1 and 2 literal zeroes.
Upvotes: 2