lauthiamkok — 2010-04-10T11:21:43-04:00 — #1
I have pictures kept in the folder like this www.mywebsite.com/img_content/extra/
there are list of pictures like,
so I want to rewrite the url from, for instance,
which mean you only see this on your browser url,
this is my code in .Htaccess file but it won't work,
RewriteRule ^wallpapers/([a_zA_Z0_9]+)\\.(jpg|gif)$ /img_content/extra/$1.$2 [L]
Many thanks if you have any ideas.
jake_arkinstall — 2010-04-10T11:27:28-04:00 — #2
I believe your problem lies in your filename regular expression:
The underscores are incorrect.
You need to allow all letters, all numbers and underscores. Fortunately there is a shorthand for [A-Za-z0-9_] which is \w:
RewriteRule ^wallpapers/(\\w+)\\.(jpg|gif)$ /img_content/extra/$1.$2 [L]
If that shorthand doesn't work in APACHE (it normally works in PHP and Perl), try the following:
RewriteRule ^wallpapers/([A-Za-z0-9_]+)\\.(jpg|gif)$ /img_content/extra/$1.$2 [L]
lauthiamkok — 2010-04-10T11:44:44-04:00 — #3
Hello! thanks for the reply.
I have just tried this code with \w but it still won't work...
I found another short hand for that which is .+ and it works fine...
RewriteRule ^wallpapers/(.+)\\.(jpg|gif)$ /img_content/extra/$1.$2 [L]
dklynn — 2010-04-11T06:28:08-04:00 — #4
That's not "short hand" but a metacharacter which stand for ANY character. With the + metacharacter as a modifier, it means one or more of anything - which can be quite dangerous. IMHO, use the character range definition Jake offered.
lauthiamkok — 2010-04-11T06:48:27-04:00 — #5
oh got it! thank you for pointing this out
stomme_poes — 2010-04-13T16:10:06-04:00 — #6
oops, in dk's post = means +
- is the metacharacter... one I tend to always mistype as = : (
dklynn — 2010-04-13T22:38:55-04:00 — #7