Can Anyone Help with Creating an Alias Using htaccess?

Discussion in 'Programming/Html' started by Furious, Jan 20, 2013.

  1. Furious

    Furious New Member

    Messages:
    7
    Likes Received:
    0
    GPU:
    2x EVGA 285 GTX (SLI)
    I am hoping to find someone that can help me with setting up an alias using htaccess.
    I'd even be happy to make a donation for your time using Paypal.

    I know a little about html and css but practically nothing about htaccess files.
    After spending 3 frustrating days googling and trying to create an alias using htaccess I am ready for some help.

    So here is what I am working with.
    I have a Synology network attached storage unit (NAS) that I am hosting from.
    The NAS is using Apache to serve up the websites.
    Below is my folder structure and URLs to access these folders:

    /volume1/web (mydomain.com)
    /volume1/web/forums (mydomain.com/forums)
    /volume1/web/example/www (mydomain.com/example/www)


    What I am wanting to do is to be able to call "mydomain.com/example" and have Apache serve up the contents of "/volume1/web/example/www", or in other words hide the "www" sub-folder from the URL.

    Anyone care to take a crack at this before my head explodes from fiddling with it? lol
     
  2. Furious

    Furious New Member

    Messages:
    7
    Likes Received:
    0
    GPU:
    2x EVGA 285 GTX (SLI)
    With a little dumb luck I managed to get this partially working.
    I created an .htaccess file in the "/volume1/web/example" folder, inside the .htaccess file I used:

    RewriteEngine On
    RewriteRule ^(.*)$ /example/www/$1 [L]


    Now when I make the URL call "http://mydomain.com/example" it is correctly showing me the index.php page of the "www" folder (/volume1/web/example/www).
    Problem now is that all links on this page are adding "/www/" back in the URL.
    Example: Clicking on "Login" goes to "http://mydomain.com/example/www/login"

    I'll keep poking at it however I feel lucky to have made it this far.
    If anyone can be of any help I would greatly appreciate it.
     
  3. chanw4

    chanw4 Ancient Guru

    Messages:
    2,297
    Likes Received:
    0
    GPU:
    ASUS GTX 670 4GB GDDR5
    I think what you need to do is to create virtual directory for the server not using the REWRITE RULE

    EDIT: Nevermind the above answer
    What you did in your second post is to redirect all the url that matchs the regex and append it to the end of /example/www/ which im surprise it works when you put http://mydomain.com/example since that will rewrite it to http://mydomain.com/example/www/example

    For your situation, i think mod_proxy would be better solution.
    ProxyRequests off
    ProxyPass /example/ http://mydomain.com/example/www/

    You also need an rewrite rule to rewrite the url /example to add the trailing '/' to the url i think. And obviously, you need to load the module in your apache config file. mod_proxy is not loaded by default i think.

    http://httpd.apache.org/docs/current/mod/mod_rewrite.html

    http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
     
    Last edited: Mar 26, 2013
  4. Furious

    Furious New Member

    Messages:
    7
    Likes Received:
    0
    GPU:
    2x EVGA 285 GTX (SLI)
    Thanks for your reply chanw4.

    I guess I forgot to update this post.
    I ended up just creating a virtual host in Apache and pointing a sub domain to it, I couldn't figure out any other method.
    The only real problem I have using the virtual host is when ever I update the firmware on my NAS (which is what I'm hosting from) I have to re-create the virtual host as it gets deleted.
    I may have that problem fixed though, won't know for sure until the next firmware update comes around.
     

Share This Page