Redirect http to https using mod_rewrite & virtualhost not w

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Redirect http to https using mod_rewrite & virtualhost not w

Postby debasishkanhar » 14. October 2014 14:56

Code: Select all
NameVirtualHost *:80
<VirtualHost *:80>
   ServerName localhost
   DocumentRoot "C:/xampp/htdocs"
   Redirect permanent /secure https://localhost/xampp/nitu/login/
</VirtualHost>

<VirtualHost _default_:443>
   ServerName localhost
   DocumentRoot "C:/xampp/htdocs"
   SSLEngine On
# etc...
</VirtualHost>


his is my virtual code file in httpd-ssl.conf.

And the following is my httpd.conf file (for mod_rewrite)

Code: Select all
<IfModule mod_rewrite.c>
    RewriteEngine On
   # Redirect /login folder to https
    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} xampp/nitu/login
    RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
</IfModule>


The following is my httpd-xampp.conf
Code: Select all
<IfModule alias_module>
Alias /security "C:/xampp/htdocs/xampp/nitu/login/"
<Directory "C:/xampp/htdocs/xampp/nitu/login/">
    <IfModule php5_module>
       <Files "status.php">
          php_admin_flag safe_mode off
       </Files>
    </IfModule>
    AllowOverride AuthConfig
   SSLRequireSSL
</Directory>


Whenever I try starting apache from xampp control panel it doesnt start and shows error. The error.log file shows the following :
[Tue Oct 14 18:34:49.705552 2014] [ssl:error] [pid 6096:tid 1668] [client ::1:56952] AH02219: access to C:/xampp/htdocs/xampp/nitu/login/ failed, reason: SSL connection required


I dont know what I'm doing wrong. Its kinda urgent so any help would be grateful.
Thanks in advance.
debasishkanhar
 
Posts: 5
Joined: 07. September 2011 12:11

Re: Redirect http to https using mod_rewrite & virtualhost n

Postby Nobbie » 14. October 2014 16:28

It dont understand what you are doing there, could please exlain in words, what you want to do?
Nobbie
 
Posts: 13165
Joined: 09. March 2008 13:04

Re: Redirect http to https using mod_rewrite & virtualhost n

Postby debasishkanhar » 14. October 2014 17:30

Hi Nobbie,

Thanks for reply. I am trying to create ssl certificate and use it with my login script. The root for login script is at C:/xampp/htdocs/xampp/nitu/login.
I followed the http://robsnotebook.com/xampp-ssl-encrypt-passwords link to create ssl certicicate.

I made my root folder(nitu/login) accessable hrough SSL only. (Using SSLRequireSSL).
Now when I try to redirect my http traffic for that folder to https using mod_rewrite of virtualhost, m unable to do so.

If I use only mod_rewrite as mentioned in the article, I get error "Access Forbidden".
If I try using virtualhost(by editing in httpd-ssl.conf) my apache server wont start.

Please say where I'm doing wrong?
debasishkanhar
 
Posts: 5
Joined: 07. September 2011 12:11

Re: Redirect http to https using mod_rewrite & virtualhost n

Postby Nobbie » 14. October 2014 20:41

I still dont understand.

Why do you want ro redirect http to https? And where did you do this (there is NO *general* redirect from http to https, nowhere). I am still missing lots of information. You have a very weired configuration, but far more, the error message does not fit your configuration.

Please still explain more precisely, what URL should users enter and what do want to do with that URL?!

P.S.: In case you are baffled - I enter "http://localhost/somefolder/somefile.html" - what should happen with that?
Nobbie
 
Posts: 13165
Joined: 09. March 2008 13:04

Re: Redirect http to https using mod_rewrite & virtualhost n

Postby debasishkanhar » 14. October 2014 22:25

The following code in my httpd-xampp.conf makes me access my root directory (in this case http://localhost/xampp/nitu/login) usimg only https mode.

Code: Select all
<IfModule alias_module>
Alias /security "C:/xampp/htdocs/xampp/nitu/login/"
<Directory "C:/xampp/htdocs/xampp/nitu/login/">
    <IfModule php5_module>
       <Files "status.php">
          php_admin_flag safe_mode off
       </Files>
    </IfModule>
    AllowOverride AuthConfig
   SSLRequireSSL
</Directory>


This is because I've added SSLRequireSSL.

Hence after adding the above mentioned code to my conf file, I always get the following error if I try accessing the following URL(http://localhost/xampp/nitu/login):
Access forbidden! New XAMPP security concept. Access to requested object is only available from local network. Error 403


But if I access using the URL : https://localhost/xampp/nitu/login it works perfectly fine.

For that reason I wanted to redirect any traffic/request made to http://localhost/xampp/nitu/login to https://localhost/xampp/nitu/login (http to https)
I googled and got to know this is possible using either mod_rewrite (in httpd.conf) or virtualhost*80 or virtualhost*443 (in httpd-ssl.conf) (I've attached my code snipet for both in my question).

Using mod_rewrite doesn't solve the problem and using virtualhost gives error in starting apache service. The error log shows : access to C://xampp/htdocs/xampp/nitu/login needs to be SSL as mentioned beforehand.

Hence in short I wanna redirect any requests to https. That is if user enters http://localhost/xampp/something, the url changes to https://localhost/xampp/something and url remains the same if url entered is https://localhost/xampp/something.

I hope I can clarify what problem I'm facing. For further information do reply.

Thanks in advance.
debasishkanhar
 
Posts: 5
Joined: 07. September 2011 12:11

Re: Redirect http to https using mod_rewrite & virtualhost n

Postby gsmith » 15. October 2014 18:45

gsmith
 
Posts: 278
Joined: 29. November 2013 18:04
Location: San Diego
XAMPP version: 0.0.0
Operating System: Win 10/2012R VS 14,15,16

Re: Redirect http to https using mod_rewrite & virtualhost n

Postby debasishkanhar » 15. October 2014 19:53

Tried following that too. But as mentioned, when I use Virtualhost for redirects, my server (xampp apache) wont start and I get error. The error log shows : access to C://xampp/htdocs/xampp/nitu/login needs to be SSL as mentioned beforehand.

I ve even posted code for my virtualhost earlier on. I'm supposed to add that to httpd-ssl.conf file right?
debasishkanhar
 
Posts: 5
Joined: 07. September 2011 12:11


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 144 guests