davideo7
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_screens hots/saves 14/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_screens hots/saves 14/14###$2 [R,L]
So my question is, what is the single digit wildcard that can be used in this?
Thanks.
RewriteCond %{REQUEST_URI} .*user_screenshots/14.*
RewriteRule ^(.*)user_screenshots/14(.
If # was a single digit wildcard, this is what that code would look like:
RewriteCond %{REQUEST_URI} .*user_screenshots/14###.*
RewriteRule ^(.*)user_screenshots/14##
So my question is, what is the single digit wildcard that can be used in this?
Thanks.
ASKER
designatedinitializer: What if I want a wildcard of just 3 digits?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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_screens hots/saves 14/14[0-9] [0-9][0-9] $2 [R,L]
RewriteCond %{REQUEST_URI} .*user_screenshots/14[0-9]
RewriteRule ^(.*)user_screenshots/14[0
yep
14[0-9][0-9][0-9]
will match 14000 through 14999.
14[0-9][0-9][0-9]
will match 14000 through 14999.
ASKER
designatedinitializer: That didn't work exactly as expected, but close. It turned this url
http://www.vizzed.com/vizzedboard/retro/user_screenshots/14514/Super%20Mario%20World_Jul20%2015_00_55.png
into this
http://www.vizzed.com/vizzedboard/retro/user_screenshots/saves14/14%5B0-9%5D%5B0-9%5D%5B0-9%5D/Super%20Mario%20World_Jul20%2015_00_55.png
but it should've turned that url into this:
http://www.vizzed.com/vizzedboard/retro/user_screenshots/saves14/14514/Super%20Mario%20World_Jul20%2015_00_55.png
http://www.vizzed.com/vizzedboard/retro/user_screenshots/14514/Super%20Mario%20World_Jul20%2015_00_55.png
into this
http://www.vizzed.com/vizzedboard/retro/user_screenshots/saves14/14%5B0-9%5D%5B0-9%5D%5B0-9%5D/Super%20Mario%20World_Jul20%2015_00_55.png
but it should've turned that url into this:
http://www.vizzed.com/vizzedboard/retro/user_screenshots/saves14/14514/Super%20Mario%20World_Jul20%2015_00_55.png
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.
What exactly are you trying to acomplish?
The example you give above shows two equal strings.
ASKER
designatedinitializer: These 2 strings aren't the same, I'll place them next to each other so you can see the difference better.
http://www.vizzed.com/vizzedboard/retro/user_screenshots/saves14/14%5B0-9%5D%5B0-9%5D%5B0-9%5D/Super%20Mario%20World_Jul20%2015_00_55.png
http://www.vizzed.com/vizzedboard/retro/user_screenshots/saves14/14514/Super%20Mario%20World_Jul20%2015_00_55.png
http://www.vizzed.com/vizzedboard/retro/user_screenshots/saves14/14%5B0-9%5D%5B0-9%5D%5B0-9%5D/Super%20Mario%20World_Jul20%2015_00_55.png
http://www.vizzed.com/vizzedboard/retro/user_screenshots/saves14/14514/Super%20Mario%20World_Jul20%2015_00_55.png
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
I was able to figure out the 2nd half of the problem on my own but designatedinitializer helped me with the first half. Thanks.
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)