Link to home
Start Free TrialLog in
Avatar of davideo7
davideo7Flag for United States of America

asked on

htaccess Rewrite Single Digit Wildcard

Is there a single digit wildcard that can be used with RewriteRule?  Here's an example, this is my current code:

RewriteCond %{REQUEST_URI} .*user_screenshots/14.*
RewriteRule ^(.*)user_screenshots/14(.*)$ http://%{HTTP_HOST}/$1user_screenshots/saves14/14$2 [R,L]

If # was a single digit wildcard, this is what that code would look like:

RewriteCond %{REQUEST_URI} .*user_screenshots/14###.*
RewriteRule ^(.*)user_screenshots/14###(.*)$ http://%{HTTP_HOST}/$1user_screenshots/saves14/14###$2 [R,L]

So my question is, what is the single digit wildcard that can be used in this?

Thanks.
Avatar of designatedinitializer
designatedinitializer
Flag of Portugal image

mod_rewrite accepts regular expressions.
if you want to match 0 or more characters use a single question mark (?).
If you want to match a digit use a character class like this:

[0-9]

(square brackets included)
Avatar of davideo7

ASKER

designatedinitializer: What if I want a wildcard of just 3 digits?
ASKER CERTIFIED SOLUTION
Avatar of designatedinitializer
designatedinitializer
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
designatedinitializer: So would it look like this?

RewriteCond %{REQUEST_URI} .*user_screenshots/14[0-9][0-9][0-9].*
RewriteRule ^(.*)user_screenshots/14[0-9][0-9][0-9](.*)$ http://%{HTTP_HOST}/$1user_screenshots/saves14/14[0-9][0-9][0-9]$2 [R,L]
yep

14[0-9][0-9][0-9]

 will match 14000 through 14999.
I was talking about the wildcard/regexp you asked about.
What exactly are you trying to acomplish?
The example you give above shows two equal strings.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,
Yeah, you're right.
You could also do it like this: (14[0-9][0-9][0-9])/(.*)
And then use $1$2

The brackets turn the match pattern into a group.
The $n stuff refers to the n'ths group matched back there.
I was able to figure out the 2nd half of the problem on my own but designatedinitializer helped me with the first half.  Thanks.