Apache: redirect content to other folder based on url

Let’s say you want to store a js library (like dojo) outside your website folder so that your backup is not polluted by this heavy framework.

You can configure apache so that every query starting with /dojo/ will be directed to this folder instead of default application folder.
Note: using subdomains creates a huge overhead with dojo => prefer this url-based redirection.

Here are the steps, they rely on mod_alias apache module, so ensure it is activated:

  1. in httpd or .htaccess, define the following rule:
    Alias /dojo <path_to_dojo_folder>
    <Directory <path_to_dojo_folder>>
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>

    Note1: don’t forget to replace “dojo” with whatever suits your needs
    Note2: apache configuration of directory might requiere more fine tuning so that directory is not listed when queried via url

  2. Restart apache if need be (ie. if modif performed in httpd.conf)
  3. Test it (try mydomain.conf/dojo/dojo/dojo.js, you should see dojo js page)

That’s it!
You now have dojo in a separate folder, up and running

sources

Post a Comment

Your email is never published nor shared. You're allow to say what you want...