logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: [SOLVED] Issue with redirection to HTTPS under XAMPP
Author
alain.roger



Joined: 24 Feb 2016
Posts: 4
Location: Slovakia

PostPosted: Thu 20 Apr '17 21:56    Post subject: [SOLVED] Issue with redirection to HTTPS under XAMPP Reply with quote

Hello,

i installed XAMPP on my ubuntu and i wanted to create virtualhost editing the appropriate file /extra/httpd-vhosts.conf

as following:

Code:
# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot "/opt/lampp/docs/dummy-host.example.com"
#    ServerName dummy-host.example.com
#    ServerAlias www.dummy-host.example.com
#    ErrorLog "logs/dummy-host.example.com-error_log"
#    CustomLog "logs/dummy-host.example.com-access_log" common
#</VirtualHost>

#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host2.example.com
#    DocumentRoot "/opt/lampp/docs/dummy-host2.example.com"
#    ServerName dummy-host2.example.com
#    ErrorLog "logs/dummy-host2.example.com-error_log"
#    CustomLog "logs/dummy-host2.example.com-access_log" common
#</VirtualHost>

<VirtualHost jobportal-admin.loc:80>
  DocumentRoot "/opt/lampp/htdocs/jobportal-admin/"
  ServerName www.jobportal-admin.loc
  ServerAlias jobportal-admin.loc
  ErrorLog "logs/jobportal-admin.loc-error_log"
  CustomLog "logs/jobportal-admin.loc.com-access_log" common
  Options Indexes FollowSymLinks Includes ExecCGI
  DirectoryIndex index.php

   <Directory "/opt/lampp/htdocs/jobportal-admin">
        Options All
        AllowOverride All
        Require all granted
  </Directory>
</VirtualHost>

<VirtualHost jobportal-admin.loc:443>
    DocumentRoot "/opt/lampp/htdocs/jobportal-admin/"
    ServerName www.jobportal-admin.loc
    ServerAlias jobportal-admin.loc

    Options Indexes FollowSymLinks Includes ExecCGI
   
    DirectoryIndex index.php

    SSLEngine on
    SSLCertificateFile "/opt/lampp/etc/ssl.crt/server.crt"
    SSLCertificateKeyFile "/opt/lampp/etc/ssl.key/server.key"
    ErrorLog "logs/jobportal-admin.loc-error_log"
    CustomLog "logs/jobportal-admin.loc.com-access_log" common
   
    <Directory "/opt/lampp/htdocs/jobportal-admin">
        Options All
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>



redirection is performed by a .htaccess file as following:

Code:
RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www.jobportal-admin\.loc/ [NC]
#RewriteRule ^/?(.*) https://www.jobportal-admin.loc/$1 [R,L]
#RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.jobportal-admin.loc/$1 [R,L]a


Any idea why it does not redirect to HTTPS each call from HHTP to the same adress ?

thx


Last edited by alain.roger on Fri 21 Apr '17 17:49; edited 1 time in total
Back to top
Jan-E



Joined: 09 Mar 2012
Posts: 1248
Location: Amsterdam, NL, EU

PostPosted: Fri 21 Apr '17 12:01    Post subject: Reply with quote

There may be some typos in the .htaccess. A single redirection inside the <VirtualHost jobportal-admin.loc:80> directive should be enough:

Code:
   <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond   %{HTTP_HOST}   ^(jobportal-admin.loc|www.jobportal-admin.loc)$
      RewriteRule   ^/(.*)         https://www.jobportal-admin.loc/$1 [R]
   </IfModule>
Back to top
alain.roger



Joined: 24 Feb 2016
Posts: 4
Location: Slovakia

PostPosted: Fri 21 Apr '17 17:04    Post subject: Reply with quote

That works great in case of development machine.

But i would like to be able to reproduce the same situation on production server, and in this case i do not have access to virtualhost tags....only to .htaccess file.

That's why i would like to solve this topic using the .htaccess file only.

thx
Back to top
Jan-E



Joined: 09 Mar 2012
Posts: 1248
Location: Amsterdam, NL, EU

PostPosted: Fri 21 Apr '17 17:26    Post subject: Reply with quote

Try this one:

Code:
RewriteEngine on
RewriteCond   %{HTTPS}      !=on
RewriteCond   %{HTTP_HOST}   ^(jobportal-admin.loc|www.jobportal-admin.loc)$
RewriteRule   ^/(.*)         https://www.jobportal-admin.loc/$1 [R=301,L]

Or use one of the solutions at http://stackoverflow.com/questions/4398951/force-ssl-https-using-htaccess-and-mod-rewrite
Back to top
alain.roger



Joined: 24 Feb 2016
Posts: 4
Location: Slovakia

PostPosted: Fri 21 Apr '17 17:47    Post subject: Reply with quote

in fact it did not work.

But in your link i found that replacing the rewrite rule by:

RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

works, so thx a lot.
Back to top
Jan-E



Joined: 09 Mar 2012
Posts: 1248
Location: Amsterdam, NL, EU

PostPosted: Fri 21 Apr '17 17:50    Post subject: Reply with quote

Probably the domainname on the production server does not end in .loc. Anyway, solved.
Back to top


Reply to topic   Topic: [SOLVED] Issue with redirection to HTTPS under XAMPP View previous topic :: View next topic
Post new topic   Forum Index -> Apache