php - Mod_ReWrite regex unknown variables count? -


i store uploaded files @ /storage/ way

  • public-adam-luki-uploads-123783.jpg

  • park-hanna-adel-propic-uploads-787689.jpg

the '-' count unknown because slice pic description

i want users able access as

  • http://site.com/public/adam/luki/uploads/123783.jpg

  • http://site.com/park/hanna/adel/propic/uploads/787689.jpg

i think same problem here

mod_rewrite unknown number of variables

but can't because i'm new mod_rewrite module

i hope can me guys right rewriterule

the question link doesn't trying (although principle same) convert url get variables.

if want convert / - can use simple rewrite rule run in loop:

rewriterule ^(.*)/(.*)$ $1-$2 [l] 

there of course few caveats that...

firstly, if trying real directory/file rule still switch out / , - , leave 404. can around adding conditions; stop rewriting real files:

rewritecond %{request_filename} !-f 

you better limit matches images (jpgs):

rewritecond %{request_filename} !-f rewriterule ^(.*)/(.*)\.jpg$ $1-$2.jpg [l] 

preferred solution

rewritecond %{request_filename} !-f rewriterule ^images/(.*)/(.*)uploads[-/](\d+)\.jpg$ images/$1-$2uploads-$3.jpg [l] rewritecond %{request_filename} !-f rewriterule ^images/(.*)$ storage/$1 [l] 

this solution requires use urls like:

http://site.com/images/park/hanna/adel/propic/uploads/787689.jpg 

the pseudo directory images means can sure url 1 want redirect , doesn't break other images/links on site.

the above rules take url (like example above) , transforms so:

images/park/hanna/adel/propic/uploads/787689.jpg    <--- original images/park-hanna/adel/propic/uploads-787689.jpg images/park-hanna-adel/propic/uploads-787689.jpg images/park-hanna-adel-propic/uploads-787689.jpg images/park-hanna-adel-propic-uploads-787689.jpg storage/park-hanna-adel-propic-uploads-787689.jpg   <--- final 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -