0

Apache: Map the example.com/12345.html URL on filesystem to /var/www/html/1/2/3/4/5/12345.html

So every letter of the URL after the example.com is a subfolder under /var/www/html. How can I solve this?

Edit: it should hande the url size dynamically, so it should work with /1/2/12.html too

Edit2: My attempt:

ScriptAliasMatch "^/([a-zA-Z0-9]+)([a-zA-Z0-9]+)([a-zA-Z0-9]+)([a-zA-Z0-9]+)([a-zA-Z0-9]+).html"   "/$1/$2/$3/$4/$5/$1$2$3$4$5.html"

but it doesn't work...

Edit3: OK It works, but with only 5 characters in the url: /12345.html

RewriteRule "^/([a-zA-Z0-9]+)([a-zA-Z0-9]+)([a-zA-Z0-9]+)([a-zA-Z0-9]+)([a-zA-Z0-9]+).html" "/var/www/html/$1/$2/$3/$4/$5/$1$2$3$4$5.html"

How can I make it dynamically?

Edit3: This is my new attempt:

RewriteEngine on
RewriteRule "^/([a-zA-Z0-9]+)([a-zA-Z0-9]+)([a-zA-Z0-9]+)([a-zA-Z0-9]+)([a-zA-Z0-9]+).html" "/var/www/html/$1/$2/$3/$4/$5/$1$2$3$4$5.html"
RewriteRule "^/([a-zA-Z0-9]+)([a-zA-Z0-9]+)([a-zA-Z0-9]+).html" "/var/www/html/$1/$2/$3/$1$2$3.html"
RewriteRule "^/([a-zA-Z0-9]+)([a-zA-Z0-9]+).html" "/var/www/html/$1/$2/$1$2.html"

Do I need to create a rule for every URL length? 3 to 20?

Roberto
  • 167
  • 1
  • 3
  • 19
  • 1
    You should be able to solve your homework yourself, otherwise you won't learn anything... So take a look at the documentation and some examples... Hint: you need a rewriting rule for that... – arkascha Mar 13 '17 at 15:17
  • Yes, I've already find that, but how can I make it dinamically? so it should work with /1/2/12.html too. – Roberto Mar 13 '17 at 15:22
  • I can't spot the attempt you make to even solve the simple case. So please add your current solution which you claim you already found to the question. Thanks. – arkascha Mar 13 '17 at 15:24

0 Answers0