Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

htaccess Rewrite Single Digit Wildcard

Posted on 2012-03-24
11
Medium Priority
?
482 Views
Last Modified: 2012-03-29
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.
0
Comment
Question by:davideo7
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37761615
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)
0
 

Author Comment

by:davideo7
ID: 37761659
designatedinitializer: What if I want a wildcard of just 3 digits?
0
 
LVL 7

Accepted Solution

by:
designatedinitializer earned 2000 total points
ID: 37761745
that's 3 times the same formula:

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

Notice that this matches any 3 digits.
It won't match 2 digits, nor 1 digit, nor no digits at all.
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Comment

by:davideo7
ID: 37761764
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]
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37761830
yep

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

 will match 14000 through 14999.
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37761981
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.
0
 

Assisted Solution

by:davideo7
davideo7 earned 0 total points
ID: 37762033
Ok I figured it out, I had to rewrite my code 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$2$3$4$5 [R,L]

Had to put brackets around the [0-9] and had to add $2$3$4 in there.
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37762946
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.
0
 

Author Closing Comment

by:davideo7
ID: 37780971
I was able to figure out the 2nd half of the problem on my own but designatedinitializer helped me with the first half.  Thanks.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question