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.
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]
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]
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.
oh got it! thank you for pointing this out
oops, in dk's post = means +
- is the metacharacter... one I tend to always mistype as = : (