You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Dennis Madsen <de...@demaweb.dk> on 2006/03/02 18:06:22 UTC

[users@httpd] Rewrite on Windows-server (subdomain)

I have this rewrite rule:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.myhp\.dk$
RewriteCond %{1} !^www$
RewriteCond c:/www/myhp.dk/www/%1 -d
RewriteCond %{REQUEST_FILENAME} !^c:/www/myhp.dk/www/
RewriteRule (.*) c:/www/myhp.dk/www/%1/$1 [l]

It's placed in my .htaccess on  <http://www.myhp.dk> http://www.myhp.dk.

When I visit myhp.dk it works but when I try to visit ns-ekstra.myhp.dk e.g.
I get this error:

You don't have permission to access /c:/www/myhp.dk/www/ns-ekstra/ on this
server.

Can anybody help me to get this rewrite work?
I would like to lead users who vist asubdomain.myhp.dk to
myhp.dk/asubdomain.

 

I get this error in my log:

80.164.67.235 - - [02/Mar/2006:14:18:35 +0100]
[admin.myhp.dk/sid#602558][rid#c52b38/initial] (3) [per-dir
C:/www/myhp.dk/www/] strip per-dir prefix: C:/www/myhp.dk/www/ -> 
80.164.67.235 - - [02/Mar/2006:14:18:35 +0100]
[admin.myhp.dk/sid#602558][rid#c52b38/initial] (3) [per-dir
C:/www/myhp.dk/www/] applying pattern '(.*)' to uri ''
80.164.67.235 - - [02/Mar/2006:14:18:35 +0100]
[admin.myhp.dk/sid#602558][rid#c52b38/initial] (2) [per-dir
C:/www/myhp.dk/www/] rewrite  -> c:/www/myhp.dk/www/admin/
80.164.67.235 - - [02/Mar/2006:14:18:35 +0100]
[admin.myhp.dk/sid#602558][rid#c52b38/initial] (3) [per-dir
C:/www/myhp.dk/www/] add per-dir prefix: c:/www/myhp.dk/www/admin/ ->
C:/www/myhp.dk/www/c:/www/myhp.dk/www/admin/
80.164.67.235 - - [02/Mar/2006:14:18:35 +0100]
[admin.myhp.dk/sid#602558][rid#c52b38/initial] (2) [per-dir
C:/www/myhp.dk/www/] strip document_root prefix:
C:/www/myhp.dk/www/c:/www/myhp.dk/www/admin/ -> /c:/www/myhp.dk/www/admin/
80.164.67.235 - - [02/Mar/2006:14:18:35 +0100]
[admin.myhp.dk/sid#602558][rid#c52b38/initial] (1) [per-dir
C:/www/myhp.dk/www/] internal redirect with /c:/www/myhp.dk/www/admin/
[INTERNAL REDIRECT]

It's easy to see that the rewrite make a mistake and end up with:
/c:/www/myhp.dk/www/admin/

It should just be:
c:/www/myhp.dk/www/admin/

 


SV: SV: SV: [users@httpd] Rewrite on Windows-server (subdomain)

Posted by Dennis Madsen <de...@demaweb.dk>.
Hei,

I'm so happy - it succeded :)
Thanks for your help.

Med venlig hilsen / Best regards
Dennis Madsen
 
DeMaWeb
http://www.demaweb.dk
CVR-nr.: 2895 9486
-----Oprindelig meddelelse-----
Fra: Robert Ionescu [mailto:robsiegen@googlemail.com] 
Sendt: 5. marts 2006 20:49
Til: users@httpd.apache.org
Emne: Re: SV: SV: [users@httpd] Rewrite on Windows-server (subdomain)

Dennis Madsen wrote:
> The requested operation has failed.

Is this being logged into your error.log?

I'm not sure if this is just a posting issue, but some line breaks are 
missing:

> RewriteEngine On
> RewriteCond %{HTTP_HOST} ^([^.]+)\.myhp\.dk$ RewriteCond %1 !^www$
> RewriteCond c:/www/myhp.dk/www/%1 -d RewriteRule ^(.*) /%1/$1 [L]

This should be 5 lines in total

RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.myhp\.dk$
RewriteCond %1 !^www$
RewriteCond c:/www/myhp.dk/www/%1 -d
RewriteRule ^(.*) /%1/$1 [L]

Did you check the syntax of the httpd.conf with "apache -t"?

-- 
Robert

---------------------------------------------------------------------
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




---------------------------------------------------------------------
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


Re: SV: SV: [users@httpd] Rewrite on Windows-server (subdomain)

Posted by Robert Ionescu <ro...@googlemail.com>.
Dennis Madsen wrote:
> The requested operation has failed.

Is this being logged into your error.log?

I'm not sure if this is just a posting issue, but some line breaks are 
missing:

> RewriteEngine On
> RewriteCond %{HTTP_HOST} ^([^.]+)\.myhp\.dk$ RewriteCond %1 !^www$
> RewriteCond c:/www/myhp.dk/www/%1 -d RewriteRule ^(.*) /%1/$1 [L]

This should be 5 lines in total

RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.myhp\.dk$
RewriteCond %1 !^www$
RewriteCond c:/www/myhp.dk/www/%1 -d
RewriteRule ^(.*) /%1/$1 [L]

Did you check the syntax of the httpd.conf with "apache -t"?

-- 
Robert

---------------------------------------------------------------------
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


SV: SV: [users@httpd] Rewrite on Windows-server (subdomain)

Posted by Dennis Madsen <de...@demaweb.dk>.
Hei,

I still have problems.
My Virtual Host is:

<VirtualHost *>
DocumentRoot c:/www/myhp.dk/www
ServerName myhp.dk
ServerAlias *.myhp.dk
ServerAdmin admin@myhp.dk
php_admin_value open_basedir c:/www/myhp.dk/www/
CustomLog c:/www/myhp.dk/access.log combined
ErrorLog c:/www/myhp.dk/error.log
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.myhp\.dk$ RewriteCond %1 !^www$
RewriteCond c:/www/myhp.dk/www/%1 -d RewriteRule ^(.*) /%1/$1 [L]
</VirtualHost>

I restart Apache without any errors, but when I visit myhp.dk I get this
error on the server:
The requested operation has failed.

Can you help me? Any logs?

Med venlig hilsen / Best regards
Dennis Madsen
-----Oprindelig meddelelse-----
Fra: Robert Ionescu [mailto:robsiegen@googlemail.com] 
Sendt: 3. marts 2006 15:01
Til: users@httpd.apache.org
Emne: Re: SV: [users@httpd] Rewrite on Windows-server (subdomain)

Dennis Madsen wrote:
> Should I insert a rewrite rule in my virtual host for myhp.dk? I have
this:
> 
> <VirtualHost *>
> DocumentRoot c:/www/myhp.dk/www
> ServerName myhp.dk
> ServerAlias *.myhp.dk
> ServerAdmin admin@myhp.dk
> php_admin_value open_basedir c:/www/myhp.dk/www/
> CustomLog c:/www/myhp.dk/access.log combined
> ErrorLog c:/www/myhp.dk/error.log
> </VirtualHost>

Hello Dennis.

In this case (rewrite within the document root), you can easily use 
inside your <virtualhost *> (just add the rules somewhere between the 
other directives):

RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.myhp\.dk$
RewriteCond %1 !^www$
RewriteCond c:/www/myhp.dk/www/%1 -d
RewriteRule ^(.*) /%1/$1 [L]

You don't need any looping protection here, because there is no internal 
redirect in per-server context. Since you're on a windows system, there 
are no concerns about security. But if would use e.g. Linux, I'd 
strongly recommend to prefix the substitution with the document root 
(like RewriteRule ^(.*) /var/www/html/%1/$1 [L]), but again, there is no 
need here to use RewriteRule ^(.*) c:/www/myhp.dk/www/%1/$1 [L]

So you might test the rules inside your <virtualhost *>.

-- 
Robert

---------------------------------------------------------------------
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




---------------------------------------------------------------------
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


SV: SV: [users@httpd] Rewrite on Windows-server (subdomain)

Posted by Dennis Madsen <de...@demaweb.dk>.
Sorry, but can you help me?

Med venlig hilsen / Best regards
Dennis Madsen
 
DeMaWeb
http://www.demaweb.dk
CVR-nr.: 2895 9486
-----Oprindelig meddelelse-----
Fra: Robert Ionescu [mailto:robsiegen@googlemail.com] 
Sendt: 3. marts 2006 15:01
Til: users@httpd.apache.org
Emne: Re: SV: [users@httpd] Rewrite on Windows-server (subdomain)

Dennis Madsen wrote:
> Should I insert a rewrite rule in my virtual host for myhp.dk? I have
this:
> 
> <VirtualHost *>
> DocumentRoot c:/www/myhp.dk/www
> ServerName myhp.dk
> ServerAlias *.myhp.dk
> ServerAdmin admin@myhp.dk
> php_admin_value open_basedir c:/www/myhp.dk/www/
> CustomLog c:/www/myhp.dk/access.log combined
> ErrorLog c:/www/myhp.dk/error.log
> </VirtualHost>

Hello Dennis.

In this case (rewrite within the document root), you can easily use 
inside your <virtualhost *> (just add the rules somewhere between the 
other directives):

RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.myhp\.dk$
RewriteCond %1 !^www$
RewriteCond c:/www/myhp.dk/www/%1 -d
RewriteRule ^(.*) /%1/$1 [L]

You don't need any looping protection here, because there is no internal 
redirect in per-server context. Since you're on a windows system, there 
are no concerns about security. But if would use e.g. Linux, I'd 
strongly recommend to prefix the substitution with the document root 
(like RewriteRule ^(.*) /var/www/html/%1/$1 [L]), but again, there is no 
need here to use RewriteRule ^(.*) c:/www/myhp.dk/www/%1/$1 [L]

So you might test the rules inside your <virtualhost *>.

-- 
Robert

---------------------------------------------------------------------
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




---------------------------------------------------------------------
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


Re: SV: [users@httpd] Rewrite on Windows-server (subdomain)

Posted by Robert Ionescu <ro...@googlemail.com>.
Dennis Madsen wrote:
> Should I insert a rewrite rule in my virtual host for myhp.dk? I have this:
> 
> <VirtualHost *>
> DocumentRoot c:/www/myhp.dk/www
> ServerName myhp.dk
> ServerAlias *.myhp.dk
> ServerAdmin admin@myhp.dk
> php_admin_value open_basedir c:/www/myhp.dk/www/
> CustomLog c:/www/myhp.dk/access.log combined
> ErrorLog c:/www/myhp.dk/error.log
> </VirtualHost>

Hello Dennis.

In this case (rewrite within the document root), you can easily use 
inside your <virtualhost *> (just add the rules somewhere between the 
other directives):

RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.myhp\.dk$
RewriteCond %1 !^www$
RewriteCond c:/www/myhp.dk/www/%1 -d
RewriteRule ^(.*) /%1/$1 [L]

You don't need any looping protection here, because there is no internal 
redirect in per-server context. Since you're on a windows system, there 
are no concerns about security. But if would use e.g. Linux, I'd 
strongly recommend to prefix the substitution with the document root 
(like RewriteRule ^(.*) /var/www/html/%1/$1 [L]), but again, there is no 
need here to use RewriteRule ^(.*) c:/www/myhp.dk/www/%1/$1 [L]

So you might test the rules inside your <virtualhost *>.

-- 
Robert

---------------------------------------------------------------------
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


SV: [users@httpd] Rewrite on Windows-server (subdomain)

Posted by Dennis Madsen <de...@demaweb.dk>.
Hei Robert,

Thanks for your answer.

Sorry, but I don't understand, that you tell me to do?
Should I insert a rewrite rule in my virtual host for myhp.dk? I have this:

<VirtualHost *>
DocumentRoot c:/www/myhp.dk/www
ServerName myhp.dk
ServerAlias *.myhp.dk
ServerAdmin admin@myhp.dk
php_admin_value open_basedir c:/www/myhp.dk/www/
CustomLog c:/www/myhp.dk/access.log combined
ErrorLog c:/www/myhp.dk/error.log
</VirtualHost>

Which rewrite rule should I insert?

Best Regards
Dennis Madsen

-----Oprindelig meddelelse-----
Fra: Robert Ionescu [mailto:robsiegen@googlemail.com] 
Sendt: 2. marts 2006 22:46
Til: users@httpd.apache.org
Emne: Re: [users@httpd] Rewrite on Windows-server (subdomain)

Dennis Madsen wrote:
> I have this rewrite rule:
> 
> RewriteEngine On
> RewriteCond %{HTTP_HOST} ^([^.]+)\.myhp\.dk$
> RewriteCond %{1} !^www$
> RewriteCond c:/www/myhp.dk/www/%1 -d
> RewriteCond %{REQUEST_FILENAME} !^c:/www/myhp.dk/www/
> RewriteRule (.*) c:/www/myhp.dk/www/%1/$1 [l]

You cannot rewrite to a full physical path in per-dir context (i.e.
.htaccess configuration files, <directory...> and <location...>
sections). mod_rewrite needs an URL-path (e.g. /abc/) here for the
internal redirect.
But mod_rewrite fails here to built such an URL-path (which is always
tried if you don't rewrite directly to an URL-path).

Place your rules in your httpd.conf (=per-server context; if you're
using <virtualhosts..> in the vhost, otherwise outside of <...>-sections.

You should be able to rewrite to a full physical path in per-server context.

IMHO placing directives directly into httpd.conf should be always 
preferred instead of using .htaccess.

-- 
Robert


---------------------------------------------------------------------
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




---------------------------------------------------------------------
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


Re: [users@httpd] Rewrite on Windows-server (subdomain)

Posted by Robert Ionescu <ro...@googlemail.com>.
Dennis Madsen wrote:
> I have this rewrite rule:
> 
> RewriteEngine On
> RewriteCond %{HTTP_HOST} ^([^.]+)\.myhp\.dk$
> RewriteCond %{1} !^www$
> RewriteCond c:/www/myhp.dk/www/%1 -d
> RewriteCond %{REQUEST_FILENAME} !^c:/www/myhp.dk/www/
> RewriteRule (.*) c:/www/myhp.dk/www/%1/$1 [l]

You cannot rewrite to a full physical path in per-dir context (i.e.
.htaccess configuration files, <directory...> and <location...>
sections). mod_rewrite needs an URL-path (e.g. /abc/) here for the
internal redirect.
But mod_rewrite fails here to built such an URL-path (which is always
tried if you don't rewrite directly to an URL-path).

Place your rules in your httpd.conf (=per-server context; if you're
using <virtualhosts..> in the vhost, otherwise outside of <...>-sections.

You should be able to rewrite to a full physical path in per-server context.

IMHO placing directives directly into httpd.conf should be always 
preferred instead of using .htaccess.

-- 
Robert


---------------------------------------------------------------------
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