You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Steven Bower <db...@gmail.com> on 2009/03/11 21:06:38 UTC

[users@httpd] mod_rewrite redirect to local path issue

Hi-
I am using mod_rewrite to redirect from a sub-directory of my existing
domain to a new domain just for this section.

Here is my .htaccess file in /othersite/ (specific domains and paths
hidden):

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /othersite/

    RewriteRule ^(.*)$ http://<myotherwebsite>.com/$1 [R=301,L]
</IfModule>

When I go to <mycurrentwebsite>.com/othersite/ (or any file within this
directory) it redirects perfectly fine. The strange part is when I go to
<mycurrentwebsite>.com/othersite (with no trailing slash), I get redirected
to <myotherwebsite>.com//var/www/<mycurrentsite>.com/web/othersite/. Apache
for some reason replaces the $1 with the local path, which is a major
security issue. I would rather not have my server paths revealed in this
way.

I couldn't figure out how to fix this issue, so as a temporary "hacked"
solution by forcing a redirect from "/var/www..." to "/" using mod_rewrite.
This is a very poor work around since my path is still being revealed behind
the scenes.

All my Google searches have turned up empty. Any help would be appreciated.

I am running Apache Version 2.0.52 on CentOS 4.6

Thanks!

- Steven Bower

Re: [users@httpd] mod_rewrite redirect to local path issue

Posted by Bob Ionescu <bo...@googlemail.com>.
2009/3/11 Steven Bower <db...@gmail.com>:
> Hi-
> I am using mod_rewrite to redirect from a sub-directory of my existing
> domain to a new domain just for this section.
> Here is my .htaccess file in /othersite/ (specific domains and paths
> hidden):
> <IfModule mod_rewrite.c>
>     RewriteEngine on
>     RewriteBase /othersite/
>     RewriteRule ^(.*)$ http://<myotherwebsite>.com/$1 [R=301,L]
> </IfModule>
> When I go to <mycurrentwebsite>.com/othersite/ (or any file within this
> directory) it redirects perfectly fine. The strange part is when I go to
> <mycurrentwebsite>.com/othersite (with no trailing slash), I get redirected
> to <myotherwebsite>.com//var/www/<mycurrentsite>.com/web/othersite/. Apache
> for some reason replaces the $1 with the local path, which is a major
> security issue. I would rather not have my server paths revealed in this
> way.
[...]
> I am running Apache Version 2.0.52 on CentOS 4.6

IIRC this issue is fixed in the 2.2 branch.

Workaround: Put the rules into /.htaccess instead of /othersite/.htaccess with

    RewriteEngine on
    RewriteBase /
    RewriteRule ^othersite/?(.*)$ http://<myotherwebsite>.com/$1 [R=301,L]

But anyway: Unless you're using other RewriteRules which may conflict
with the Redirect directives provided by mod_alias, use mod_alias for
such a simple redirection instead of mod_rewrite:

Redirect 301 /othersite http://<myotherwebsite>.com

Bob

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org