You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Richard Taubo <or...@bergersen.no> on 2011/08/17 15:27:37 UTC
[users@httpd] ServerAlias and RewriteRule
Hi!
I originally set my virtual host up like this in my httpd.conf file:
<VirtualHost *:80>
....
ServerName www.example.com
ServerAlias example.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
</VirtualHost>
Running curl to check the setup I get:
[$] curl example.com
Result:
---------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
...
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://www.example.com//">here</a>.</p>
...
---------------------------------------------------
As you can see from the link "The document has moved . . . ", href is set to: href="http://www.example.com//",
i.e. with TWO slashes after and not ONE slash.
To fix it i changed the RewriteRule
From:
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
To:
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
and now the "301 Moved Permanently" HTML page gives:
The document has moved <a href="http://www.example.com/">here</a>
Question 1)
Are there any problems running a):
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
Rather than b):
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
?
Will e.g. a slash always be added as a part of $1 in a) if it exists in the
original url query (as caught by the RewriteCond shown above)?
Question 2)
Is the method I use to alias "example.com" with "www.example.com",
a good way to set up a ServerAlias in my httpd.conf file, or are there better ways?
My current method, as mentioned above, is:
ServerName www.example.com
ServerAlias example.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
Thanks for any input!
Richard Taubo
---------------------------------------------------------------------
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] ServerAlias and RewriteRule
Posted by Frank Gingras <fr...@gmail.com>.
On 09/15/2011 05:35 PM, Rajeev Prasad wrote:
> thank you Terry,
> even th ebelow mesg was from yahoo, had rich text formatting...
> but i have resent my mesg in plain text, lets see.
>
> *From:* Terry Carmen <te...@cnysupport.com>
> *To:* users@httpd.apache.org
> *Sent:* Thursday, September 15, 2011 2:38 PM
> *Subject:* Re: [users@httpd] ServerAlias and RewriteRule
>
> Quoting Rajeev Prasad <rp...@yahoo.com>:
>
> > Hello,
> >
> > I am not sure why I my emails are getting this error (and not being
> > published in list), when i send a fresh email to list.
>
> FREEMAIL_FROM,
> HTML_MESSAGE,
> RCVD_IN_DNSWL_NONE,
> SPF_PASS,
> URI_OBFU_WWW
>
> Because you're sending from Yahoo, which has a history of abuse, you
> sent an HTML message to a text-only mailing list, your mail server is
> not trusted by dnswl.org, and your email apparently contained a URL that
> looked suspicious.
>
> Terry
>
>
>
> >
> >
> > body
> >
> > any advice?
> > thank you.
> > Rajeev
> >
> >
> >
> > From: Tom Evans <te...@googlemail.com>
> > To: users@httpd.apache.org
> > Sent: Wednesday, August 17, 2011 11:03 AM
> > Subject: Re: [users@httpd] ServerAlias and RewriteRule
> >
> > On Wed, Aug 17, 2011 at 4:56 PM, Richard Taubo <or...@bergersen.no> wrote:
> >> Thanks!
> >>
> >> So to be 110% clear, since this is kind of important to get right :-)
> >>
> >> 1) So either this – leave off the / from the end of the rewritten URL:
> >> RewriteRule ^(.*)$ http://www.example.com$1
> <http://www.example.com$1/> [L,R=301]
> >>
> >> 2) Or this – not capture the slash from the original URL:
> >> RewriteRule ^/(.*)$ http://www.example.com/$1 [L,R=301]
> >>
> >> 3) But not this – as was the alternative I started out with (the
> >> browsers I have tested
> >> do not seem mind, but the rewrite logs shows that an extra slash is
> added):
> >> RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
> >>
> >>>>
> >>>> Question 2)
> >>>> Is the method I use to alias "example.com" with "www.example.com",
> >>>> a good way to set up a ServerAlias in my httpd.conf file, or are
> >>>> there better ways?
> >>>> My current method, as mentioned above, is:
> >>>> ServerName www.example.com
> >>>> ServerAlias example.com
> >>>> RewriteEngine On
> >>>> RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
> >>>> RewriteRule ^(.*)$ http://www.example.com$1
> <http://www.example.com$1/> [L,R=301]
> >>>>
> >>>
> >>> It's fine. Some people prefer to have the host name canonicalization
> >>> occur in a separate vhost, as this separates the configuration for the
> >>> 'correct' hostname from the configuration for 'incorrect' hostnames.
> >>
> >> So instead of:
> >> <VirtualHost *:80>
> >> ....
> >> ServerName www.example.com
> >> ServerAlias example.com
> >> RewriteEngine On
> >> RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
> >> RewriteRule ^(.*)$ http://www.example.com$1
> <http://www.example.com$1/> [L,R=301]
> >> </VirtualHost>
> >>
> >> They would rather create two VirtualHosts like this instead:
> >> <VirtualHost *:80>
> >> ....
> >> ServerName www.example.com
> >> ....
> >> </VirtualHost>
> >>
> >> <VirtualHost *:80>
> >> ....
> >> ServerName example.com
> >> RewriteEngine On
> >> RewriteRule ^(.*)$ http://www.example.com$1
> <http://www.example.com$1/> [L,R=301]
> >> ....
> >> </VirtualHost>
> >>
> >>
> >> Appreciate your answers!
> >>
> >> Richard Taubo
> >
> > Yep, precisely. Personally I do option 2 for the first question, and
> > multiple vhosts for the second question (but a single vhost is also
> > perfectly fine).
> >
> > Cheers
> >
> > Tom
> >
> > ---------------------------------------------------------------------
> > 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
> >
> >
> >
> >
> > Sorry, we were unable to deliver your message to the following address.
> >
> > <us...@httpd.apache.org>:
> > Remote host said:552 spam score (5.3) exceeded threshold
> > (FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS,URI_OBFU_WWW
> > ) [BODY]
> --
> Terry Carmen
> CNY Support, LLC
> Web. Database. Business.
> http://www.cnysupport.com <http://www.cnysupport.com/>
>
>
Rajeev,
You replied in a non-text format, again.
Frank.
---------------------------------------------------------------------
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] ServerAlias and RewriteRule
Posted by Rajeev Prasad <rp...@yahoo.com>.
thank you Terry,
even th ebelow mesg was from yahoo, had rich text formatting...
but i have resent my mesg in plain text, lets see.
From: Terry Carmen <te...@cnysupport.com>
To: users@httpd.apache.org
Sent: Thursday, September 15, 2011 2:38 PM
Subject: Re: [users@httpd] ServerAlias and RewriteRule
Quoting Rajeev Prasad <rp...@yahoo.com>:
> Hello,
>
> I am not sure why I my emails are getting this error (and not being
> published in list), when i send a fresh email to list.
FREEMAIL_FROM,
HTML_MESSAGE,
RCVD_IN_DNSWL_NONE,
SPF_PASS,
URI_OBFU_WWW
Because you're sending from Yahoo, which has a history of abuse, you sent an HTML message to a text-only mailing list, your mail server is not trusted by dnswl.org, and your email apparently contained a URL that looked suspicious.
Terry
>
>
> body
>
> any advice?
> thank you.
> Rajeev
>
>
>
> From: Tom Evans <te...@googlemail.com>
> To: users@httpd.apache.org
> Sent: Wednesday, August 17, 2011 11:03 AM
> Subject: Re: [users@httpd] ServerAlias and RewriteRule
>
> On Wed, Aug 17, 2011 at 4:56 PM, Richard Taubo <or...@bergersen.no> wrote:
>> Thanks!
>>
>> So to be 110% clear, since this is kind of important to get right :-)
>>
>> 1) So either this – leave off the / from the end of the rewritten URL:
>> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
>>
>> 2) Or this – not capture the slash from the original URL:
>> RewriteRule ^/(.*)$ http://www.example.com/$1 [L,R=301]
>>
>> 3) But not this – as was the alternative I started out with (the
>> browsers I have tested
>> do not seem mind, but the rewrite logs shows that an extra slash is added):
>> RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
>>
>>>>
>>>> Question 2)
>>>> Is the method I use to alias "example.com" with "www.example.com",
>>>> a good way to set up a ServerAlias in my httpd.conf file, or are
>>>> there better ways?
>>>> My current method, as mentioned above, is:
>>>> ServerName www.example.com
>>>> ServerAlias example.com
>>>> RewriteEngine On
>>>> RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
>>>> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
>>>>
>>>
>>> It's fine. Some people prefer to have the host name canonicalization
>>> occur in a separate vhost, as this separates the configuration for the
>>> 'correct' hostname from the configuration for 'incorrect' hostnames.
>>
>> So instead of:
>> <VirtualHost *:80>
>> ....
>> ServerName www.example.com
>> ServerAlias example.com
>> RewriteEngine On
>> RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
>> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
>> </VirtualHost>
>>
>> They would rather create two VirtualHosts like this instead:
>> <VirtualHost *:80>
>> ....
>> ServerName www.example.com
>> ....
>> </VirtualHost>
>>
>> <VirtualHost *:80>
>> ....
>> ServerName example.com
>> RewriteEngine On
>> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
>> ....
>> </VirtualHost>
>>
>>
>> Appreciate your answers!
>>
>> Richard Taubo
>
> Yep, precisely. Personally I do option 2 for the first question, and
> multiple vhosts for the second question (but a single vhost is also
> perfectly fine).
>
> Cheers
>
> Tom
>
> ---------------------------------------------------------------------
> 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
>
>
>
>
> Sorry, we were unable to deliver your message to the following address.
>
> <us...@httpd.apache.org>:
> Remote host said:552 spam score (5.3) exceeded threshold
> (FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS,URI_OBFU_WWW
> ) [BODY]
--
Terry Carmen
CNY Support, LLC
Web. Database. Business.
http://www.cnysupport.com
Re: [users@httpd] ServerAlias and RewriteRule
Posted by Terry Carmen <te...@cnysupport.com>.
Quoting Rajeev Prasad <rp...@yahoo.com>:
> Hello,
>
> I am not sure why I my emails are getting this error (and not being
> published in list), when i send a fresh email to list.
FREEMAIL_FROM,
HTML_MESSAGE,
RCVD_IN_DNSWL_NONE,
SPF_PASS,
URI_OBFU_WWW
Because you're sending from Yahoo, which has a history of abuse, you sent an HTML message to a text-only mailing list, your mail server is not trusted by dnswl.org, and your email apparently contained a URL that looked suspicious.
Terry
>
>
> body
>
> any advice?
> thank you.
> Rajeev
>
>
>
> From: Tom Evans <te...@googlemail.com>
> To: users@httpd.apache.org
> Sent: Wednesday, August 17, 2011 11:03 AM
> Subject: Re: [users@httpd] ServerAlias and RewriteRule
>
> On Wed, Aug 17, 2011 at 4:56 PM, Richard Taubo <or...@bergersen.no> wrote:
>> Thanks!
>>
>> So to be 110% clear, since this is kind of important to get right :-)
>>
>> 1) So either this – leave off the / from the end of the rewritten URL:
>> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
>>
>> 2) Or this – not capture the slash from the original URL:
>> RewriteRule ^/(.*)$ http://www.example.com/$1 [L,R=301]
>>
>> 3) But not this – as was the alternative I started out with (the
>> browsers I have tested
>> do not seem mind, but the rewrite logs shows that an extra slash is added):
>> RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
>>
>>>>
>>>> Question 2)
>>>> Is the method I use to alias "example.com" with "www.example.com",
>>>> a good way to set up a ServerAlias in my httpd.conf file, or are
>>>> there better ways?
>>>> My current method, as mentioned above, is:
>>>> ServerName www.example.com
>>>> ServerAlias example.com
>>>> RewriteEngine On
>>>> RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
>>>> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
>>>>
>>>
>>> It's fine. Some people prefer to have the host name canonicalization
>>> occur in a separate vhost, as this separates the configuration for the
>>> 'correct' hostname from the configuration for 'incorrect' hostnames.
>>
>> So instead of:
>> <VirtualHost *:80>
>> ....
>> ServerName www.example.com
>> ServerAlias example.com
>> RewriteEngine On
>> RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
>> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
>> </VirtualHost>
>>
>> They would rather create two VirtualHosts like this instead:
>> <VirtualHost *:80>
>> ....
>> ServerName www.example.com
>> ....
>> </VirtualHost>
>>
>> <VirtualHost *:80>
>> ....
>> ServerName example.com
>> RewriteEngine On
>> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
>> ....
>> </VirtualHost>
>>
>>
>> Appreciate your answers!
>>
>> Richard Taubo
>
> Yep, precisely. Personally I do option 2 for the first question, and
> multiple vhosts for the second question (but a single vhost is also
> perfectly fine).
>
> Cheers
>
> Tom
>
> ---------------------------------------------------------------------
> 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
>
>
>
>
> Sorry, we were unable to deliver your message to the following address.
>
> <us...@httpd.apache.org>:
> Remote host said:552 spam score (5.3) exceeded threshold
> (FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS,URI_OBFU_WWW
> ) [BODY]
--
Terry Carmen
CNY Support, LLC
Web. Database. Business.
http://www.cnysupport.com
Re: [users@httpd] ServerAlias and RewriteRule
Posted by Rajeev Prasad <rp...@yahoo.com>.
Hello,
I am not sure why I my emails are getting this error (and not being published in list), when i send a fresh email to list.
body
any advice?
thank you.
Rajeev
From: Tom Evans <te...@googlemail.com>
To: users@httpd.apache.org
Sent: Wednesday, August 17, 2011 11:03 AM
Subject: Re: [users@httpd] ServerAlias and RewriteRule
On Wed, Aug 17, 2011 at 4:56 PM, Richard Taubo <or...@bergersen.no> wrote:
> Thanks!
>
> So to be 110% clear, since this is kind of important to get right :-)
>
> 1) So either this – leave off the / from the end of the rewritten URL:
> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
>
> 2) Or this – not capture the slash from the original URL:
> RewriteRule ^/(.*)$ http://www.example.com/$1 [L,R=301]
>
> 3) But not this – as was the alternative I started out with (the browsers I have tested
> do not seem mind, but the rewrite logs shows that an extra slash is added):
> RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
>
>>>
>>> Question 2)
>>> Is the method I use to alias "example.com" with "www.example.com",
>>> a good way to set up a ServerAlias in my httpd.conf file, or are there better ways?
>>> My current method, as mentioned above, is:
>>> ServerName www.example.com
>>> ServerAlias example.com
>>> RewriteEngine On
>>> RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
>>> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
>>>
>>
>> It's fine. Some people prefer to have the host name canonicalization
>> occur in a separate vhost, as this separates the configuration for the
>> 'correct' hostname from the configuration for 'incorrect' hostnames.
>
> So instead of:
> <VirtualHost *:80>
> ....
> ServerName www.example.com
> ServerAlias example.com
> RewriteEngine On
> RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
> </VirtualHost>
>
> They would rather create two VirtualHosts like this instead:
> <VirtualHost *:80>
> ....
> ServerName www.example.com
> ....
> </VirtualHost>
>
> <VirtualHost *:80>
> ....
> ServerName example.com
> RewriteEngine On
> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
> ....
> </VirtualHost>
>
>
> Appreciate your answers!
>
> Richard Taubo
Yep, precisely. Personally I do option 2 for the first question, and
multiple vhosts for the second question (but a single vhost is also
perfectly fine).
Cheers
Tom
---------------------------------------------------------------------
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
Sorry, we were unable to deliver your message to the following address.
<us...@httpd.apache.org>:
Remote host said:552 spam score (5.3) exceeded threshold (FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS,URI_OBFU_WWW ) [BODY]
Re: [users@httpd] ServerAlias and RewriteRule
Posted by Tom Evans <te...@googlemail.com>.
On Wed, Aug 17, 2011 at 4:56 PM, Richard Taubo <or...@bergersen.no> wrote:
> Thanks!
>
> So to be 110% clear, since this is kind of important to get right :-)
>
> 1) So either this – leave off the / from the end of the rewritten URL:
> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
>
> 2) Or this – not capture the slash from the original URL:
> RewriteRule ^/(.*)$ http://www.example.com/$1 [L,R=301]
>
> 3) But not this – as was the alternative I started out with (the browsers I have tested
> do not seem mind, but the rewrite logs shows that an extra slash is added):
> RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
>
>>>
>>> Question 2)
>>> Is the method I use to alias "example.com" with "www.example.com",
>>> a good way to set up a ServerAlias in my httpd.conf file, or are there better ways?
>>> My current method, as mentioned above, is:
>>> ServerName www.example.com
>>> ServerAlias example.com
>>> RewriteEngine On
>>> RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
>>> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
>>>
>>
>> It's fine. Some people prefer to have the host name canonicalization
>> occur in a separate vhost, as this separates the configuration for the
>> 'correct' hostname from the configuration for 'incorrect' hostnames.
>
> So instead of:
> <VirtualHost *:80>
> ....
> ServerName www.example.com
> ServerAlias example.com
> RewriteEngine On
> RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
> </VirtualHost>
>
> They would rather create two VirtualHosts like this instead:
> <VirtualHost *:80>
> ....
> ServerName www.example.com
> ....
> </VirtualHost>
>
> <VirtualHost *:80>
> ....
> ServerName example.com
> RewriteEngine On
> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
> ....
> </VirtualHost>
>
>
> Appreciate your answers!
>
> Richard Taubo
Yep, precisely. Personally I do option 2 for the first question, and
multiple vhosts for the second question (but a single vhost is also
perfectly fine).
Cheers
Tom
---------------------------------------------------------------------
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] ServerAlias and RewriteRule
Posted by Richard Taubo <or...@bergersen.no>.
On 17. aug. 2011, at 15.36, Tom Evans wrote:
> On Wed, Aug 17, 2011 at 2:27 PM, Richard Taubo <or...@bergersen.no> wrote:
>> Hi!
>>
>> I originally set my virtual host up like this in my httpd.conf file:
>>
>> <snip>
>>
>> Question 1)
>> Are there any problems running a):
>> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
>> Rather than b):
>> RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
>> ?
>> Will e.g. a slash always be added as a part of $1 in a) if it exists in the
>> original url query (as caught by the RewriteCond shown above)?
>
> All URLs start with a /. When you 'curl example.com', curl requests
> the URL '/' from the host 'example.com'. This is captured by your
> rewrite rule.
> So no, a slash is never added, the slash is captured from the original
> URL. You can either not capture the slash from the original URL, or
> leave off the / from the end of the rewritten URL, whichever makes you
> feel more comfortable.
Thanks!
So to be 110% clear, since this is kind of important to get right :-)
1) So either this – leave off the / from the end of the rewritten URL:
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
2) Or this – not capture the slash from the original URL:
RewriteRule ^/(.*)$ http://www.example.com/$1 [L,R=301]
3) But not this – as was the alternative I started out with (the browsers I have tested
do not seem mind, but the rewrite logs shows that an extra slash is added):
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
>>
>> Question 2)
>> Is the method I use to alias "example.com" with "www.example.com",
>> a good way to set up a ServerAlias in my httpd.conf file, or are there better ways?
>> My current method, as mentioned above, is:
>> ServerName www.example.com
>> ServerAlias example.com
>> RewriteEngine On
>> RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
>> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
>>
>
> It's fine. Some people prefer to have the host name canonicalization
> occur in a separate vhost, as this separates the configuration for the
> 'correct' hostname from the configuration for 'incorrect' hostnames.
So instead of:
<VirtualHost *:80>
....
ServerName www.example.com
ServerAlias example.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
</VirtualHost>
They would rather create two VirtualHosts like this instead:
<VirtualHost *:80>
....
ServerName www.example.com
....
</VirtualHost>
<VirtualHost *:80>
....
ServerName example.com
RewriteEngine On
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
....
</VirtualHost>
Appreciate your answers!
Richard Taubo
---------------------------------------------------------------------
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] ServerAlias and RewriteRule
Posted by Tom Evans <te...@googlemail.com>.
On Wed, Aug 17, 2011 at 2:27 PM, Richard Taubo <or...@bergersen.no> wrote:
> Hi!
>
> I originally set my virtual host up like this in my httpd.conf file:
>
> <snip>
>
> Question 1)
> Are there any problems running a):
> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
> Rather than b):
> RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
> ?
> Will e.g. a slash always be added as a part of $1 in a) if it exists in the
> original url query (as caught by the RewriteCond shown above)?
All URLs start with a /. When you 'curl example.com', curl requests
the URL '/' from the host 'example.com'. This is captured by your
rewrite rule.
So no, a slash is never added, the slash is captured from the original
URL. You can either not capture the slash from the original URL, or
leave off the / from the end of the rewritten URL, whichever makes you
feel more comfortable.
>
> Question 2)
> Is the method I use to alias "example.com" with "www.example.com",
> a good way to set up a ServerAlias in my httpd.conf file, or are there better ways?
> My current method, as mentioned above, is:
> ServerName www.example.com
> ServerAlias example.com
> RewriteEngine On
> RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
> RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
>
It's fine. Some people prefer to have the host name canonicalization
occur in a separate vhost, as this separates the configuration for the
'correct' hostname from the configuration for 'incorrect' hostnames.
Cheers
Tom
---------------------------------------------------------------------
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