You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by David Mehler <da...@gmail.com> on 2017/07/15 01:11:36 UTC

[users@httpd] virtual host double slash effect, need solution

Hello,

I'm running Apache 2.4 on a FreeBSD 10.3 system, with several virtual
hosts. My goal is to have all of them completely ssl, except for the
.well-known area needed for letsencrypt.

I'm getting a double slash effect,

for example example.com//

and similar for other virtual hosts. I've googled and seen references
to my rewrite rules, I've changed lines below which are commented,
which did not solve the issue.

Any suggestions appreciated.
Thanks.
Dave.
PS, the ssl information is accurate on the server just not in this message.

<VirtualHost *:80>
    ServerName example.com
    RewriteEngine On
    RewriteRule ^/?(.*) http://www.example.com$1 [R,L]
# This line also produces the double slash effect
#     RewriteRule ^/?(.*) http://www.example.com/$1 [R,L]
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@example.com
    DocumentRoot "/usr/vhosts/example.com/htdocs/"
    ServerName www.example.com
    ServerAlias www.example.com mail.example.com

    ErrorDocument 404 /errordocs/error404.htm
    # share well-known for renewal via Let's Encrypt!
    Alias /.well-known/acme-challenge /usr/local/www/.well-known/acme-challenge

    # Anything that isn't going to example.com/.well-known gets
forwarded to the https site
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/.well-known
# These next two lines had the double slash effect
    #RewriteRule (.*) https://www.example.com$1 [R=301,L]
    #RewriteRule (.*) https://www.example.com/$1 [R=301,L]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

    ErrorLog "/usr/vhosts/example.com/logs/error.log"
</VirtualHost>
<VirtualHost *:443>
    ServerAdmin webmaster@example.com
    DocumentRoot "/usr/vhosts/example.com/htdocs/"
    ServerName www.example.com
SSLEngine on
SSLCertificateFile "fullchain.pem"
SSLCertificateKeyFile "privkey.pem"

    <Directory "/usr/vhosts/example.com/htdocs/">
Options FollowSymLinks
AllowOverRide None
Require all granted
    </Directory>
    <IfModule mod_log_config.c>
        CustomLog "|/usr/local/sbin/rotatelogs -l
/usr/vhosts/example.com/logs/access.log-%Y-%m-%d.log 86400" combined
    </IfModule>

# Disc cache setup
    CacheQuickHandler off
    CacheLock on
    CacheLockPath /tmp/mod_cache-lock
    CacheLockMaxAge 5
    CacheIgnoreHeaders Set-Cookie
    <Location />
        CacheEnable disk
        CacheHeader on
        CacheDefaultExpire 600
        CacheMaxExpire 86400
        CacheLastModifiedFactor 0.5
        ExpiresActive on
        ExpiresDefault "access plus 5 minutes"
        Header merge Cache-Control public
        FileETag All
    </Location>
</VirtualHost>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] virtual host double slash effect, need solution

Posted by David Mehler <da...@gmail.com>.
Hello,

Thanks. That sure made my file easier to handle.

One thing can I using redirect go from http to https? Like example.com
redirects to https://www.example.com?

Thanks.
Dave.


On 7/16/17, Daniel <df...@gmail.com> wrote:
> Redirect is simpler as you can see, it redirects everything, it has a
> regex version called RedirectMatch. Both are provided by mod_alias.
>
> RewriteRule is for more complex things, yes it can redirect too, but
> as you have seen yourself, the most simple thing can bring confusion.
> RewriteRute is provided by mod_rewrite and should be used only when
> there is no simpler option for the sake of simplicity.
>
> The rule of thumb is to go for simpler configuration directives
> whenever possible, and a simple redirection like that in virtualhost
> is a task perfect for Redirect.
>
> 2017-07-16 19:14 GMT+02:00 David Mehler <da...@gmail.com>:
>> Hello,
>>
>> Thanks. I'll try the rewrite redirect.
>>
>> With regards the redirect option, the simpler way, does it do the tls
>> conversion unsecure to secure? What would the advantages/disadvantages
>> of rewrite and redirect?
>>
>> Thanks.
>> Dave.
>>
>>
>> On 7/16/17, Daniel <df...@gmail.com> wrote:
>>> And while at it why not use simple Redirect's since your config fits
>>> perfectly to use them:
>>>
>>> <VirtualHost *:80>
>>>     ServerName example.com
>>>     Redirect / http://www.example.com/
>>> </VirtualHost>
>>>
>>> simpler, gets the job done, and you don't need a cannon to smash a fly.
>>>
>>>
>>> 2017-07-16 17:48 GMT+02:00 Luca Toscano <to...@gmail.com>:
>>>> Hi David,
>>>>
>>>> 2017-07-15 3:11 GMT+02:00 David Mehler <da...@gmail.com>:
>>>>>
>>>>> Hello,
>>>>>
>>>>> I'm running Apache 2.4 on a FreeBSD 10.3 system, with several virtual
>>>>> hosts. My goal is to have all of them completely ssl, except for the
>>>>> .well-known area needed for letsencrypt.
>>>>>
>>>>> <VirtualHost *:80>
>>>>>     ServerName example.com
>>>>>     RewriteEngine On
>>>>>     RewriteRule ^/?(.*) http://www.example.com$1 [R,L]
>>>>> # This line also produces the double slash effect
>>>>> #     RewriteRule ^/?(.*) http://www.example.com/$1 [R,L]
>>>>> </VirtualHost>
>>>>>
>>>>
>>>> Have you tried with RewriteRule ^(.*)$ https://www.example.com$1
>>>> [R=301,L]
>>>> ?
>>>> (note also the https, IIUC you need to force TLS).
>>>>
>>>> Hope that helps,
>>>>
>>>> Luca
>>>>
>>>
>>>
>>>
>>> --
>>> Daniel Ferradal
>>> IT Specialist
>>>
>>> email         dferradal at gmail.com
>>> linkedin     es.linkedin.com/in/danielferradal
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>>> For additional commands, e-mail: users-help@httpd.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>> For additional commands, e-mail: users-help@httpd.apache.org
>>
>
>
>
> --
> Daniel Ferradal
> IT Specialist
>
> email         dferradal at gmail.com
> linkedin     es.linkedin.com/in/danielferradal
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] virtual host double slash effect, need solution

Posted by Daniel <df...@gmail.com>.
Redirect is simpler as you can see, it redirects everything, it has a
regex version called RedirectMatch. Both are provided by mod_alias.

RewriteRule is for more complex things, yes it can redirect too, but
as you have seen yourself, the most simple thing can bring confusion.
RewriteRute is provided by mod_rewrite and should be used only when
there is no simpler option for the sake of simplicity.

The rule of thumb is to go for simpler configuration directives
whenever possible, and a simple redirection like that in virtualhost
is a task perfect for Redirect.

2017-07-16 19:14 GMT+02:00 David Mehler <da...@gmail.com>:
> Hello,
>
> Thanks. I'll try the rewrite redirect.
>
> With regards the redirect option, the simpler way, does it do the tls
> conversion unsecure to secure? What would the advantages/disadvantages
> of rewrite and redirect?
>
> Thanks.
> Dave.
>
>
> On 7/16/17, Daniel <df...@gmail.com> wrote:
>> And while at it why not use simple Redirect's since your config fits
>> perfectly to use them:
>>
>> <VirtualHost *:80>
>>     ServerName example.com
>>     Redirect / http://www.example.com/
>> </VirtualHost>
>>
>> simpler, gets the job done, and you don't need a cannon to smash a fly.
>>
>>
>> 2017-07-16 17:48 GMT+02:00 Luca Toscano <to...@gmail.com>:
>>> Hi David,
>>>
>>> 2017-07-15 3:11 GMT+02:00 David Mehler <da...@gmail.com>:
>>>>
>>>> Hello,
>>>>
>>>> I'm running Apache 2.4 on a FreeBSD 10.3 system, with several virtual
>>>> hosts. My goal is to have all of them completely ssl, except for the
>>>> .well-known area needed for letsencrypt.
>>>>
>>>> <VirtualHost *:80>
>>>>     ServerName example.com
>>>>     RewriteEngine On
>>>>     RewriteRule ^/?(.*) http://www.example.com$1 [R,L]
>>>> # This line also produces the double slash effect
>>>> #     RewriteRule ^/?(.*) http://www.example.com/$1 [R,L]
>>>> </VirtualHost>
>>>>
>>>
>>> Have you tried with RewriteRule ^(.*)$ https://www.example.com$1 [R=301,L]
>>> ?
>>> (note also the https, IIUC you need to force TLS).
>>>
>>> Hope that helps,
>>>
>>> Luca
>>>
>>
>>
>>
>> --
>> Daniel Ferradal
>> IT Specialist
>>
>> email         dferradal at gmail.com
>> linkedin     es.linkedin.com/in/danielferradal
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>> For additional commands, e-mail: users-help@httpd.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>



-- 
Daniel Ferradal
IT Specialist

email         dferradal at gmail.com
linkedin     es.linkedin.com/in/danielferradal

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] virtual host double slash effect, need solution

Posted by David Mehler <da...@gmail.com>.
Hello,

Thanks. I'll try the rewrite redirect.

With regards the redirect option, the simpler way, does it do the tls
conversion unsecure to secure? What would the advantages/disadvantages
of rewrite and redirect?

Thanks.
Dave.


On 7/16/17, Daniel <df...@gmail.com> wrote:
> And while at it why not use simple Redirect's since your config fits
> perfectly to use them:
>
> <VirtualHost *:80>
>     ServerName example.com
>     Redirect / http://www.example.com/
> </VirtualHost>
>
> simpler, gets the job done, and you don't need a cannon to smash a fly.
>
>
> 2017-07-16 17:48 GMT+02:00 Luca Toscano <to...@gmail.com>:
>> Hi David,
>>
>> 2017-07-15 3:11 GMT+02:00 David Mehler <da...@gmail.com>:
>>>
>>> Hello,
>>>
>>> I'm running Apache 2.4 on a FreeBSD 10.3 system, with several virtual
>>> hosts. My goal is to have all of them completely ssl, except for the
>>> .well-known area needed for letsencrypt.
>>>
>>> <VirtualHost *:80>
>>>     ServerName example.com
>>>     RewriteEngine On
>>>     RewriteRule ^/?(.*) http://www.example.com$1 [R,L]
>>> # This line also produces the double slash effect
>>> #     RewriteRule ^/?(.*) http://www.example.com/$1 [R,L]
>>> </VirtualHost>
>>>
>>
>> Have you tried with RewriteRule ^(.*)$ https://www.example.com$1 [R=301,L]
>> ?
>> (note also the https, IIUC you need to force TLS).
>>
>> Hope that helps,
>>
>> Luca
>>
>
>
>
> --
> Daniel Ferradal
> IT Specialist
>
> email         dferradal at gmail.com
> linkedin     es.linkedin.com/in/danielferradal
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] virtual host double slash effect, need solution

Posted by Daniel <df...@gmail.com>.
And while at it why not use simple Redirect's since your config fits
perfectly to use them:

<VirtualHost *:80>
    ServerName example.com
    Redirect / http://www.example.com/
</VirtualHost>

simpler, gets the job done, and you don't need a cannon to smash a fly.


2017-07-16 17:48 GMT+02:00 Luca Toscano <to...@gmail.com>:
> Hi David,
>
> 2017-07-15 3:11 GMT+02:00 David Mehler <da...@gmail.com>:
>>
>> Hello,
>>
>> I'm running Apache 2.4 on a FreeBSD 10.3 system, with several virtual
>> hosts. My goal is to have all of them completely ssl, except for the
>> .well-known area needed for letsencrypt.
>>
>> <VirtualHost *:80>
>>     ServerName example.com
>>     RewriteEngine On
>>     RewriteRule ^/?(.*) http://www.example.com$1 [R,L]
>> # This line also produces the double slash effect
>> #     RewriteRule ^/?(.*) http://www.example.com/$1 [R,L]
>> </VirtualHost>
>>
>
> Have you tried with RewriteRule ^(.*)$ https://www.example.com$1 [R=301,L] ?
> (note also the https, IIUC you need to force TLS).
>
> Hope that helps,
>
> Luca
>



-- 
Daniel Ferradal
IT Specialist

email         dferradal at gmail.com
linkedin     es.linkedin.com/in/danielferradal

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] virtual host double slash effect, need solution

Posted by Luca Toscano <to...@gmail.com>.
Hi David,

2017-07-15 3:11 GMT+02:00 David Mehler <da...@gmail.com>:

> Hello,
>
> I'm running Apache 2.4 on a FreeBSD 10.3 system, with several virtual
> hosts. My goal is to have all of them completely ssl, except for the
> .well-known area needed for letsencrypt.
>
> <VirtualHost *:80>
>     ServerName example.com
>     RewriteEngine On
>     RewriteRule ^/?(.*) http://www.example.com$1 [R,L]
> # This line also produces the double slash effect
> #     RewriteRule ^/?(.*) http://www.example.com/$1 [R,L]
> </VirtualHost>
>
>
Have you tried with RewriteRule ^(.*)$ https://www.example.com$1 [R=301,L]
? (note also the https, IIUC you need to force TLS).

Hope that helps,

Luca