Author |
|
paska
Joined: 12 Dec 2013 Posts: 4
|
Posted: Thu 12 Dec '13 18:24 Post subject: RewriteRule webroot to file-system path |
|
|
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: 7373 Location: Germany, Next to Hamburg
|
Posted: Thu 12 Dec '13 18:43 Post subject: |
|
|
Your rewrite rule need to start with ^(.*)$ |
|
Back to top |
|
paska
Joined: 12 Dec 2013 Posts: 4
|
Posted: Thu 12 Dec '13 18:56 Post subject: |
|
|
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: 7373 Location: Germany, Next to Hamburg
|
Posted: Thu 12 Dec '13 21:06 Post subject: |
|
|
Sorry,
Code: |
^/somepath(.*) /otherpath$1
|
|
|
Back to top |
|
paska
Joined: 12 Dec 2013 Posts: 4
|
Posted: Thu 12 Dec '13 21:14 Post subject: |
|
|
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: 7373 Location: Germany, Next to Hamburg
|
Posted: Thu 12 Dec '13 21:29 Post subject: |
|
|
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
|
Posted: Thu 12 Dec '13 21:35 Post subject: |
|
|
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
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 |
|