# adding a domain to a http request?

## Letharion

I have a drupal site under construction.

I've set it up on my private webserver, and added a faked host to my hosts file.

When I go to www.site.com, drupal somehow picks up that domain, and loads file from a corresponding directory.

Can I somehow add this to a http request, so that 123.456.789.012/site.com redirects to www.site.com?

I hope I made some sense here, I barely understand what I'm asking myself  :Wink: 

----------

## xtz

If HTTP Redirection is what you are asking about, you can do it with the META tag:

```
<html>

        <head>

                <title>Redirecting...</title>

                <META http-equiv="refresh" content="0;URL=path/or/url/to/file">

        </head>

</html>

```

----------

## Letharion

 *xtz wrote:*   

> If HTTP Redirection is what you are asking about, you can do it with the META tag:
> 
> ```
> <html>
> 
> ...

 

Well, I haven't tried now, but I assume it wouldn't quite cut it.

If I redirect you to a domain that I don't really own, I assume you will ask your dns and won't get anywhere.

In my case however, I override the dns with my hosts file. A redirect won't do that, right?

Thinking about how I can improve my question, I realise that it's related to my apache config.

I have

```
<VirtualHost *:80>

   Include /etc/apache2/vhosts.d/default_vhost.include

   ServerName www.site.org

   DocumentRoot /var/www/localhost/htdocs/drupal

   <IfModule mpm_peruser_module>

      ServerEnvironment apache apache

   </IfModule>

</VirtualHost>
```

and since site.org doesn't really exist, I override the dns with hosts.

What I need is to fool my apache into believing that it's site.org being requested, not 123.456.789.012/site.org.

Or perhaps the apache config can be rewritten to better suit my needs.

----------

## Mad Merlin

My understanding is that you're developing a new site at site.org, but you're doing the development locally (for which site.org doesn't point to). If it wasn't for name based virtual hosting, you could just go to localhost/site.org, provided you had the site as a subdirectory of your default vhost. You really want to simulate production locally though, and the easiest way to do that is to define site.org in /etc/hosts (pointing to localhost, or the local machine with your development copy), then go to site.org itself, not localhost/site.org, and it'll work.

----------

## Letharion

 *Mad Merlin wrote:*   

> My understanding is that you're developing a new site at site.org, but you're doing the development locally (for which site.org doesn't point to). If it wasn't for name based virtual hosting, you could just go to localhost/site.org, provided you had the site as a subdirectory of your default vhost. You really want to simulate production locally though, and the easiest way to do that is to define site.org in /etc/hosts (pointing to localhost, or the local machine with your development copy), then go to site.org itself, not localhost/site.org, and it'll work.

 

You are precisely right! BUT, I've already done that.

And now, lets say I want you to see that page too, how do I do that?

I could instruct you to set up your hosts file, right? But now this person is not very technical, and I have failed to set things up over the phone.

Then what do I do?

----------

## Mad Merlin

 *Letharion wrote:*   

>  *Mad Merlin wrote:*   My understanding is that you're developing a new site at site.org, but you're doing the development locally (for which site.org doesn't point to). If it wasn't for name based virtual hosting, you could just go to localhost/site.org, provided you had the site as a subdirectory of your default vhost. You really want to simulate production locally though, and the easiest way to do that is to define site.org in /etc/hosts (pointing to localhost, or the local machine with your development copy), then go to site.org itself, not localhost/site.org, and it'll work. 
> 
> You are precisely right! BUT, I've already done that.
> 
> And now, lets say I want you to see that page too, how do I do that?
> ...

 

Then, unfortunately, you're out of luck, at least with simple solutions.

You'll need some sort of proxy in front of the request so that you can transform it into the desired request. One option would be to use mod_rewrite in Apache and rewrite notsite.org/site.org/foo to site.org/foo, and because you have site.org defined in /etc/hosts on /that/ machine properly, Apache ultimately sees the request as for site.org/foo and responds accordingly. Another option is to use something like www-servers/pound to actually proxy the requests, where you can also mangle them as you please, but mod_rewrite is probably easiest.

----------

## Letharion

I was hoping php could do some magic.

Oh well, maybe I'll try over the phone again then.

----------

## Mad Merlin

 *Letharion wrote:*   

> I was hoping php could do some magic.
> 
> Oh well, maybe I'll try over the phone again then.

 

The proxy need not be on another machine, try this in Apache:

```

RewriteEngine on

RewriteCond %{SERVER_NAME} notsite.org

RewriteRule ^/site\.org/(.+)$ http://site.org/$1 [L]

```

Assuming you have site.org stored at notsite.org/site.org, the above will transparently rewrite the urls for you.

----------

## Letharion

 *Mad Merlin wrote:*   

>  *Letharion wrote:*   I was hoping php could do some magic.
> 
> Oh well, maybe I'll try over the phone again then. 
> 
> The proxy need not be on another machine, try this in Apache:
> ...

 

Ah, then it can be done quite easy after all  :Smile: 

As I don't quite understand the syntax, I might be missing something.

In httpd.conf, just after loading modules:

```
RewriteEngine on

RewriteCond %{SERVER_NAME} 87.251.215.19

RewriteRule ^/drupal/(.+)$ http://infozinzino.org/$1 [L]
```

In default vhosts:

```
<VirtualHost *:80>

   Include /etc/apache2/vhosts.d/default_vhost.include

   ServerName www.infozinzino.org

   DocumentRoot /var/www/localhost/htdocs/drupal

   <IfModule mpm_peruser_module>

      ServerEnvironment apache apache

   </IfModule>

</VirtualHost>
```

This redirect does not work, and going to 87.251.215.19/drupal lands me in that directory. (Asking me if I want to install drupal)

And I did restart apache  :Smile: 

----------

## Mad Merlin

Try enabling the rewrite log, it may have some illuminating clues:

```

RewriteLog /var/log/apache2/rewrite_log

RewriteLogLevel 9

```

Also, for your use, you probably want .*, not .+, but I don't think that's the main problem here.

You can also output the vhost in your apache logs, add %v to your currently used log format in /etc/apache2/modules.d/00_mod_log_config.conf.

----------

## Letharion

I changed the + to *, and here's the result from the rewrite log, which I'm not sure howto read.

```
85.227.194.3 - - [26/Apr/2009:22:18:53 +0200] [87.251.215.19/sid#b80f6bb8][rid#b82cf668/initial] (3) [perdir /var/www/localhost/htdocs/drupal/] strip per-dir prefix: /var/www/localhost/htdocs/drupal/ ->

85.227.194.3 - - [26/Apr/2009:22:18:53 +0200] [87.251.215.19/sid#b80f6bb8][rid#b82cf668/initial] (3) [perdir /var/www/localhost/htdocs/drupal/] applying pattern '^(.*)$' to uri ''

85.227.194.3 - - [26/Apr/2009:22:18:53 +0200] [87.251.215.19/sid#b80f6bb8][rid#b82cf668/initial] (4) [perdir /var/www/localhost/htdocs/drupal/] RewriteCond: input='/var/www/localhost/htdocs/drupal/' pattern='!-f' => matched

85.227.194.3 - - [26/Apr/2009:22:18:53 +0200] [87.251.215.19/sid#b80f6bb8][rid#b82cf668/initial] (4) [perdir /var/www/localhost/htdocs/drupal/] RewriteCond: input='/var/www/localhost/htdocs/drupal/' pattern='!-d' => not-matched

85.227.194.3 - - [26/Apr/2009:22:18:53 +0200] [87.251.215.19/sid#b80f6bb8][rid#b82cf668/initial] (1) [perdir /var/www/localhost/htdocs/drupal/] pass through /var/www/localhost/htdocs/drupal/

85.227.194.3 - - [26/Apr/2009:22:18:53 +0200] [87.251.215.19/sid#b80f6bb8][rid#b82dfb80/subreq] (3) [perdir /var/www/localhost/htdocs/drupal/] strip per-dir prefix: /var/www/localhost/htdocs/drupal/index.php -> index.php

85.227.194.3 - - [26/Apr/2009:22:18:53 +0200] [87.251.215.19/sid#b80f6bb8][rid#b82dfb80/subreq] (3) [perdir /var/www/localhost/htdocs/drupal/] applying pattern '^(.*)$' to uri 'index.php'

85.227.194.3 - - [26/Apr/2009:22:18:53 +0200] [87.251.215.19/sid#b80f6bb8][rid#b82dfb80/subreq] (4) [perdir /var/www/localhost/htdocs/drupal/] RewriteCond: input='/var/www/localhost/htdocs/drupal/index.php' pattern='!-f' => not-matched

85.227.194.3 - - [26/Apr/2009:22:18:53 +0200] [87.251.215.19/sid#b80f6bb8][rid#b82dfb80/subreq] (1) [perdir /var/www/localhost/htdocs/drupal/] pass through /var/www/localhost/htdocs/drupal/index.php

85.227.194.3 - - [26/Apr/2009:22:18:53 +0200] [87.251.215.19/sid#b80f6bb8][rid#b82cb658/initial] (3) [perdir /var/www/localhost/htdocs/drupal/] strip per-dir prefix: /var/www/localhost/htdocs/drupal/install.php -> install.php

85.227.194.3 - - [26/Apr/2009:22:18:53 +0200] [87.251.215.19/sid#b80f6bb8][rid#b82cb658/initial] (3) [perdir /var/www/localhost/htdocs/drupal/] applying pattern '^(.*)$' to uri 'install.php'

85.227.194.3 - - [26/Apr/2009:22:18:53 +0200] [87.251.215.19/sid#b80f6bb8][rid#b82cb658/initial] (4) [perdir /var/www/localhost/htdocs/drupal/] RewriteCond: input='/var/www/localhost/htdocs/drupal/install.php' pattern='!-f' => not-matched

85.227.194.3 - - [26/Apr/2009:22:18:53 +0200] [87.251.215.19/sid#b80f6bb8][rid#b82cb658/initial] (1) [perdir /var/www/localhost/htdocs/drupal/] pass through /var/www/localhost/htdocs/drupal/install.php

85.227.194.3 - - [26/Apr/2009:22:18:55 +0200] [87.251.215.19/sid#b80f6bb8][rid#b82cf668/initial] (3) [perdir /var/www/localhost/htdocs/drupal/] strip per-dir prefix: /var/www/localhost/htdocs/drupal/install.php -> install.php

85.227.194.3 - - [26/Apr/2009:22:18:55 +0200] [87.251.215.19/sid#b80f6bb8][rid#b82cf668/initial] (3) [perdir /var/www/localhost/htdocs/drupal/] applying pattern '^(.*)$' to uri 'install.php'

85.227.194.3 - - [26/Apr/2009:22:18:55 +0200] [87.251.215.19/sid#b80f6bb8][rid#b82cf668/initial] (4) [perdir /var/www/localhost/htdocs/drupal/] RewriteCond: input='/var/www/localhost/htdocs/drupal/install.php' pattern='!-f' => not-matched

85.227.194.3 - - [26/Apr/2009:22:18:55 +0200] [87.251.215.19/sid#b80f6bb8][rid#b82cf668/initial] (1) [perdir /var/www/localhost/htdocs/drupal/] pass through /var/www/localhost/htdocs/drupal/install.php
```

I'm guessing that "currently used log format" is common? If I add %v after %b however, nothing gets written to the rewrite_log.

```
<IfModule log_config_module>

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

LogFormat "%h %l %u %t \"%r\" %>s %b" common

LogFormat "%{Referer}i -> %U" referer

LogFormat "%{User-Agent}i" agent

LogFormat "%v %h %l %u %t \"%r\" %>s %b %T" script

LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" VLOG=%{VLOG}e" vhost

<IfModule logio_module>

# You need to enable mod_logio.c to use %I and %O

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio

LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" vhostio

</IfModule>

CustomLog /var/log/apache2/access_log common

</IfModule>
```

----------

## Mad Merlin

```

85.227.194.3 - - [26/Apr/2009:22:18:53 +0200] [87.251.215.19/sid#b80f6bb8][rid#b82cf668/initial] (4) [perdir /var/www/localhost/htdocs/drupal/] RewriteCond: input='/var/www/localhost/htdocs/drupal/' pattern='!-f' => matched 

85.227.194.3 - - [26/Apr/2009:22:18:53 +0200] [87.251.215.19/sid#b80f6bb8][rid#b82cf668/initial] (4) [perdir /var/www/localhost/htdocs/drupal/] RewriteCond: input='/var/www/localhost/htdocs/drupal/' pattern='!-d' => not-matched

```

I'm not sure what's happening in these lines, I've never seen that before. But it looks like it's not actually rewriting the urls because of it.

 *Letharion wrote:*   

> I'm guessing that "currently used log format" is common? If I add %v after %b however, nothing gets written to the rewrite_log. 

 

Yes, but that goes into your access_log, not your rewrite_log.

----------

