logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: RewriteRule webroot to file-system path
Author
paska



Joined: 12 Dec 2013
Posts: 4

PostPosted: Thu 12 Dec '13 18:24    Post subject: RewriteRule webroot to file-system path Reply with quote

Hi folks !

I've checked out lots of topics here and there regarding the issue in question, but no results yet.

So here is the issue.

Two projects:

    proj: site.loc
    proj2.0: newsite.loc


They are located in different places on the file system. And i need to redirect from one project to another internally, so url for site.loc is preserved.
E.g. requesting site.loc/hey/there i need apache to serve files form proj2.0.

First, i know that on the .htaccess level we cannot use RewriteRule to file-system path (for security reasons).
Okay, an Alias is a workaround.

Say i add an Alias to virtual host as following:

Code:
Alias /newsite /some/path/to/proj2.0


Then if i'll add the rule to proj's .htaccess:

Code:
RewriteRule ^hey/there /newsite


This will work.

But, the webroot does not work:
Code:

RewriteRule ^$ /newsite


Is it i'm doing something wrong or there is some quirk about the webroot ?

Thanks in advance
        Back to top
        James Blond
        Moderator


        Joined: 19 Jan 2006
        Posts: 7294
        Location: Germany, Next to Hamburg

        PostPosted: Thu 12 Dec '13 18:43    Post subject: Reply with quote

        Your rewrite rule need to start with ^(.*)$
        Back to top
        paska



        Joined: 12 Dec 2013
        Posts: 4

        PostPosted: Thu 12 Dec '13 18:56    Post subject: Reply with quote

        i need only 'redirect'/rewrite rules for specific paths.

        e.g.: only '/some/path' and webroot,
        but leave any other ones as is,
        pointing to the old project.
        Back to top
        James Blond
        Moderator


        Joined: 19 Jan 2006
        Posts: 7294
        Location: Germany, Next to Hamburg

        PostPosted: Thu 12 Dec '13 21:06    Post subject: Reply with quote

        Sorry,

        Code:

        ^/somepath(.*) /otherpath$1
        Back to top
        paska



        Joined: 12 Dec 2013
        Posts: 4

        PostPosted: Thu 12 Dec '13 21:14    Post subject: Reply with quote

        James Blond wrote:
        Sorry,

        Code:

        ^/somepath(.*) /otherpath$1


        yes, this will work, but not webroot.

        how do i rewrite rule for e.g.:
        http://site.loc to be served code from proj2.0
        ?
        Back to top
        James Blond
        Moderator


        Joined: 19 Jan 2006
        Posts: 7294
        Location: Germany, Next to Hamburg

        PostPosted: Thu 12 Dec '13 21:29    Post subject: Reply with quote

        The hard think is to rewrite the document root, but not all the other stuff. So you have to exclude all other paths...

        Code:

        #exclude here all other paths!
        RewriteRule ^/(dir_name|file_name\.extension|and_so_on) - [L]
        # rewrite the one
        RewriteRule ^/some/path(.*) /otherpath$1 [L]
        # rewrite document root 
        RewriteRule ^(.*)$ /path/to/proj2.0/$1 [L]



        Well I think it would be better to have different vhosts.
        Back to top
        paska



        Joined: 12 Dec 2013
        Posts: 4

        PostPosted: Thu 12 Dec '13 21:35    Post subject: Reply with quote

        James Blond wrote:
        The hard think is to rewrite the document root, but not all the other stuff. So you have to exclude all other paths...

        Code:

        #exclude here all other paths!
        RewriteRule ^/(dir_name|file_name\.extension|and_so_on) - [L]
        # rewrite the one
        RewriteRule ^/some/path(.*) /otherpath$1 [L]
        # rewrite document root 
        RewriteRule ^(.*)$ /path/to/proj2.0/$1 [L]



        Well I think it would be better to have different vhosts.


        yeah, i think it's not an option.
        (just don't know all other paths by heart Smile

        but i still don't understand what's the root cause ?
        why webroot cannot be RewriteRule'd using Alias ?

        E.g. this is valid and will work:

        Code:

        RewriteRule ^$ http://google.com
        Back to top


        Reply to topic   Topic: RewriteRule webroot to file-system path View previous topic :: View next topic
        Post new topic   Forum Index -> Apache