You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Marc Jacobs <pu...@wav.es> on 2007/07/28 08:19:16 UTC
help on apache mod_rewrite
Hi everyone,
I have a problem with apache, perhaps you can help... I would be glad
if you did. I'm not an expert on the subject, so forgive me if I'm
sounding naive....
I need to create 1 virtual host that runs multiple sites (siteA.com) &
siteB.com) located at different paths in the host.
In order to achieve this:
- I've already configured DNS for these domains
- I've created a virtual host named: sites (/var/www/vhosts/sites/httpdocs)
- Under sites, I have 2 seperate directories:
- siteA and SiteB
- Now I want to configure apache so that, the virtual host will
resolve correct paths for each of these domains (siteA.com &
SiteB.com)
- However, no matter what I did in httpd.conf, the virtual host won't
resolve the right folders for these domains
See the part of httpd.conf that relates to this virtual host:
<VirtualHost *:80>
DocumentRoot /var/www/vhosts/sites/httpdocs
ServerName sites
ServerAlias siteA.com www.siteA.com siteB.com www.SiteB.com
RewriteEngine On
# THIS IS NOT WORKING: this was intended to take you to the right path
when you type siteA.com OR www.siteA.com
RewriteCond %{HTTP_HOST} ^siteA\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.siteA\.com$ [NC]
RewriteRule ^/var/www/vhosts/sites/httpdocs(.*)
/var/www/vhosts/sites/httpdocs/siteA$1
# THIS IS NOT WORKING: this was intended take you to the right path
when you type siteB.com OR www.siteB.com
RewriteCond %{HTTP_HOST} ^siteB\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.siteB\.com$ [NC]
RewriteRule ^/var/www/vhosts/sites/httpdocs(.*)
/var/www/vhosts/sites/httpdocs/siteB$1
</VirtualHost>
I think I'm making a mistake with the RewriteRule part, rather than
RewriteCond. I tried to understand these (.*)!$ stuff... But they're
not very intuitive, i'm afraid.
Thank for your time.
Cheers,
Re: [users@httpd] Re: help on apache mod_rewrite
Posted by Matus UHLAR - fantomas <uh...@fantomas.sk>.
On 28.07.07 09:30, Marc Jacobs wrote:
> I have a problem with apache, perhaps you can help... I would be glad
> if you did. I'm not an expert on the subject, so forgive me if I'm
> sounding naive....
>
> I need to create 1 virtual host that runs multiple sites (siteA.com) &
> siteB.com) located at different paths in the host.
I do not understand. Why do you think you need to run two "sites" in one
virtual host? The "sites" are called "virtual hosts" in apache.
--
Matus UHLAR - fantomas, uhlar@fantomas.sk ; http://www.fantomas.sk/
Warning: I wish NOT to receive e-mail advertising to this address.
Varovanie: na tuto adresu chcem NEDOSTAVAT akukolvek reklamnu postu.
Boost your system's speed by 500% - DEL C:\WINDOWS\*.*
---------------------------------------------------------------------
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] help on apache mod_rewrite
Posted by Norman Peelman <np...@cfl.rr.com>.
Tim Bannister wrote:
> On 28 Jul 2007, at 07:30, Marc Jacobs wrote:
>
>> I need to create 1 virtual host that runs multiple sites (siteA.com) &
>> siteB.com) located at different paths in the host.
> …
>> See the part of httpd.conf that relates to this virtual host:
>>
>> <VirtualHost *:80>
>> DocumentRoot /var/www/vhosts/sites/httpdocs
>> ServerName sites
>> ServerAlias siteA.com www.siteA.com siteB.com www.SiteB.com
>> RewriteEngine On
>> # THIS IS NOT WORKING: this was intended to take you to the right
>> path when you type siteA.com OR www.siteA.com
>> RewriteCond %{HTTP_HOST} ^siteA\.com$ [NC,OR]
>> RewriteCond %{HTTP_HOST} ^www\.siteA\.com$ [NC]
>> RewriteRule ^/var/www/vhosts/sites/httpdocs(.*)
>> /var/www/vhosts/sites/httpdocs/siteA$1
>> # THIS IS NOT WORKING: this was intended take you to the right path
>> when you type siteB.com OR www.siteB.com
>> RewriteCond %{HTTP_HOST} ^siteB\.com$ [NC,OR]
>> RewriteCond %{HTTP_HOST} ^www\.siteB\.com$ [NC]
>> RewriteRule ^/var/www/vhosts/sites/httpdocs(.*)
>> /var/www/vhosts/sites/httpdocs/siteB$1
>> </VirtualHost>
>
> Try this; it could be along the line of what you want:
> RewriteEngine On
> RewriteCond %{HTTP_HOST} ^siteA\.com$ [NC,OR]
> RewriteCond %{HTTP_HOST} ^www\.siteA\.com$ [NC]
> RewriteRule ^/(.*)$ /var/www/vhosts/sites/httpdocs/siteA/$1
> # and similarly for siteB
>
> If you also use Alias directives, they might be affected by this.
> Check that errors (eg 404) still look right with the configuration in
> place.
>
> --Tim Bannister - +44 7980408788 - isoma@jellybaby.net
>
>
> ---------------------------------------------------------------------
> 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
>
I think rewrite* is overkill for this really. Although i've not
messed around with ServerAlias, I usually just duplicate the VH entries
with the appropriate ServerNames. I think it's easier to make mods to
each individual site that way.
Long way...
<virtualhost *>
ServerName siteA.com
...
</virtualhost *>
<virtualhost>
ServerName www.siteA.com
...
</virtualhost>
<virtualhost *>
ServerName siteB.com
...
</virtualhost *>
<virtualhost>
ServerName www.siteB.com
...
</virtualhost>
or simply try
Short way...
<virtualhost *>
ServerName siteA.com
ServerAlias www.siteA.com
...
</virtualhost>
<virtualhost *>
ServerName siteB.com
ServerAlias www.siteB.com
...
</virtualhost>
I'm still using the long way for now... no reason really other than i'm
too lazy to change it. :)
Norm
---------------------------------------------------------------------
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] help on apache mod_rewrite
Posted by Tim Bannister <is...@jellybaby.net>.
On 28 Jul 2007, at 07:30, Marc Jacobs wrote:
> I need to create 1 virtual host that runs multiple sites (siteA.com) &
> siteB.com) located at different paths in the host.
…
> See the part of httpd.conf that relates to this virtual host:
>
> <VirtualHost *:80>
> DocumentRoot /var/www/vhosts/sites/httpdocs
> ServerName sites
> ServerAlias siteA.com www.siteA.com siteB.com www.SiteB.com
> RewriteEngine On
> # THIS IS NOT WORKING: this was intended to take you to the right
> path when you type siteA.com OR www.siteA.com
> RewriteCond %{HTTP_HOST} ^siteA\.com$ [NC,OR]
> RewriteCond %{HTTP_HOST} ^www\.siteA\.com$ [NC]
> RewriteRule ^/var/www/vhosts/sites/httpdocs(.*) /var/www/vhosts/
> sites/httpdocs/siteA$1
> # THIS IS NOT WORKING: this was intended take you to the right path
> when you type siteB.com OR www.siteB.com
> RewriteCond %{HTTP_HOST} ^siteB\.com$ [NC,OR]
> RewriteCond %{HTTP_HOST} ^www\.siteB\.com$ [NC]
> RewriteRule ^/var/www/vhosts/sites/httpdocs(.*) /var/www/vhosts/
> sites/httpdocs/siteB$1
> </VirtualHost>
Try this; it could be along the line of what you want:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^siteA\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.siteA\.com$ [NC]
RewriteRule ^/(.*)$ /var/www/vhosts/sites/httpdocs/siteA/$1
# and similarly for siteB
If you also use Alias directives, they might be affected by this.
Check that errors (eg 404) still look right with the configuration in
place.
--
Tim Bannister - +44 7980408788 - isoma@jellybaby.net
---------------------------------------------------------------------
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
[users@httpd] Re: help on apache mod_rewrite
Posted by Marc Jacobs <pu...@wav.es>.
Hi everyone,
I have a problem with apache, perhaps you can help... I would be glad
if you did. I'm not an expert on the subject, so forgive me if I'm
sounding naive....
I need to create 1 virtual host that runs multiple sites (siteA.com) &
siteB.com) located at different paths in the host.
In order to achieve this:
- I've already configured DNS for these domains
- I've created a virtual host named: sites (/var/www/vhosts/sites/httpdocs)
- Under sites, I have 2 seperate directories:
- siteA and SiteB
- Now I want to configure apache so that, the virtual host will
resolve correct paths for each of these domains (siteA.com &
SiteB.com)
- However, no matter what I did in httpd.conf, the virtual host won't
resolve the right folders for these domains
See the part of httpd.conf that relates to this virtual host:
<VirtualHost *:80>
DocumentRoot /var/www/vhosts/sites/httpdocs
ServerName sites
ServerAlias siteA.com www.siteA.com siteB.com www.SiteB.com
RewriteEngine On
# THIS IS NOT WORKING: this was intended to take you to the right path
when you type siteA.com OR www.siteA.com
RewriteCond %{HTTP_HOST} ^siteA\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.siteA\.com$ [NC]
RewriteRule ^/var/www/vhosts/sites/httpdocs(.*)
/var/www/vhosts/sites/httpdocs/siteA$1
# THIS IS NOT WORKING: this was intended take you to the right path
when you type siteB.com OR www.siteB.com
RewriteCond %{HTTP_HOST} ^siteB\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.siteB\.com$ [NC]
RewriteRule ^/var/www/vhosts/sites/httpdocs(.*)
/var/www/vhosts/sites/httpdocs/siteB$1
</VirtualHost>
I think I'm making a mistake with the RewriteRule part, rather than
RewriteCond. I tried to understand these (.*)!$ stuff... But they're
not very intuitive, i'm afraid.
Thank for your time.
Cheers,
Re: help on apache mod_rewrite
Posted by Arnold Daniels <in...@adaniels.nl>.
Hi Marc,
This is not the correct list for you question. This list is for
developers of the apache http server only.
Use to following to get a bit more info of what is going on:
RewriteLog /var/log/rewrite.log
RewriteLogLevel 2
The `stuff` you are talking about are regular expressions and are not
exclusive to mod_rewrite. Check http://www.regular-expressions.info for
a tutorial.
Best regards,
Arnold
Marc Jacobs wrote:
> Hi everyone,
>
> I have a problem with apache, perhaps you can help... I would be glad
> if you did. I'm not an expert on the subject, so forgive me if I'm
> sounding naive....
>
> I need to create 1 virtual host that runs multiple sites (siteA.com) &
> siteB.com) located at different paths in the host.
>
> In order to achieve this:
> - I've already configured DNS for these domains
> - I've created a virtual host named: sites (/var/www/vhosts/sites/httpdocs)
> - Under sites, I have 2 seperate directories:
> - siteA and SiteB
> - Now I want to configure apache so that, the virtual host will
> resolve correct paths for each of these domains (siteA.com &
> SiteB.com)
> - However, no matter what I did in httpd.conf, the virtual host won't
> resolve the right folders for these domains
>
> See the part of httpd.conf that relates to this virtual host:
>
> <VirtualHost *:80>
> DocumentRoot /var/www/vhosts/sites/httpdocs
> ServerName sites
> ServerAlias siteA.com www.siteA.com siteB.com www.SiteB.com
> RewriteEngine On
> # THIS IS NOT WORKING: this was intended to take you to the right path
> when you type siteA.com OR www.siteA.com
> RewriteCond %{HTTP_HOST} ^siteA\.com$ [NC,OR]
> RewriteCond %{HTTP_HOST} ^www\.siteA\.com$ [NC]
> RewriteRule ^/var/www/vhosts/sites/httpdocs(.*)
> /var/www/vhosts/sites/httpdocs/siteA$1
> # THIS IS NOT WORKING: this was intended take you to the right path
> when you type siteB.com OR www.siteB.com
> RewriteCond %{HTTP_HOST} ^siteB\.com$ [NC,OR]
> RewriteCond %{HTTP_HOST} ^www\.siteB\.com$ [NC]
> RewriteRule ^/var/www/vhosts/sites/httpdocs(.*)
> /var/www/vhosts/sites/httpdocs/siteB$1
> </VirtualHost>
>
>
> I think I'm making a mistake with the RewriteRule part, rather than
> RewriteCond. I tried to understand these (.*)!$ stuff... But they're
> not very intuitive, i'm afraid.
>
> Thank for your time.
>
> Cheers,
>