Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
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.
| |
|
Topic: Problems using rewrite from https to http |
|
Author |
|
RussDavidson
Joined: 21 Sep 2006 Posts: 4
|
Posted: Thu 21 Sep '06 4:50 Post subject: Problems using rewrite from https to http |
|
|
Hey,
What I'm trying to do:
Set up Apache so that when a person requests particular directories on my site, they are forced to use https, however if they request any other area of the site, they are forced to use http.
What I've tried:
I can get the rewrite rule to work fine for redirecting from http to https for a given directory by using the following code in httpd.conf
------ httpd.conf
RewriteCond %{SERVER_PORT} !443
RewriteCond %{REQUEST_URI} ^/ssl
RewriteRule ^(.*)$ https://my-server$1 [R=301]
------
But, I have not been able to figure out how to get it to redirect back to http for everything else.
I have tried using the same logic for the https bit above, in httpd.conf so that it looks like
------ httpd.conf
RewriteCond %{SERVER_PORT} !80
RewriteCond %{REQUEST_URI} ^/
RewriteRule ^(.*)$ http://my-server$1 [R=301]
------ [Edited the typo in the post noted by Tom]
Even with turning the rewrite logging on, it doesn't even seem like it's running this at all.
Hope that someone can point out the obvious piece that I'm missing in this puzzle, or a suggestion as to how to do it another way.
Thanks in advance,
Russ
Last edited by RussDavidson on Thu 21 Sep '06 6:30; edited 2 times in total |
|
Back to top |
|
tdonovan Moderator
Joined: 17 Dec 2005 Posts: 611 Location: Milford, MA, USA
|
Posted: Thu 21 Sep '06 6:00 Post subject: |
|
|
Your second rule appears to have a typo.
I think you want:
RewriteRule ^(.*)$ http://my-server$1 [R=301]
not:
RewriteRule ^(.*)$ https://my-server$1 [R=301]
( i.e. the URL has http: instead of https: )
-tom- |
|
Back to top |
|
RussDavidson
Joined: 21 Sep 2006 Posts: 4
|
Posted: Thu 21 Sep '06 6:24 Post subject: |
|
|
Oops...thanks Tom, but that was a typo in my post.
I do actually have it correct in my code, so although it definitely would be the problem, it unfortunately isn't what's causing my dramas at the moment.
Cheers,
Russ |
|
Back to top |
|
RussDavidson
Joined: 21 Sep 2006 Posts: 4
|
Posted: Thu 21 Sep '06 8:26 Post subject: |
|
|
From further investigation into this, the best that I can think of at the moment is that the RewriteRule is not being run at all when the request is through https.
The test that I have tried is by adding the following line to the httpd.conf
RewriteRule ^(.*)$ https://my-server$1 [R=301]
Without any other RewriteCond, or RewriteRule's.
What I would expect to happen, is when you request a page as http, it should flip you to https...then cause an infinite loop attempting to continually redirecting you to https. But, this flips from http to https without a problem, but stops there with only serving a single page.
If I do exactly the same thing but with the rule set to go to http, such as
RewriteRule ^(.*)$ http://my-server$1 [R=301]
Then, if I request a http page, it goes into an infinitely loop of redirects (as expected), if i request a https page, only a single https page is returned.
I have also tried adding the http rule to extra/httpd-ssl.conf inside the VirtualHost element, which I have uncommented the reference to from inside httpd.conf. This has never seemed to do anything at all. |
|
Back to top |
|
Jorge
Joined: 12 Mar 2006 Posts: 376 Location: Belgium
|
|
Back to top |
|
RussDavidson
Joined: 21 Sep 2006 Posts: 4
|
Posted: Fri 22 Sep '06 3:22 Post subject: |
|
|
Thanks for the tip.
It seems that I've been able to sort out where my misunderstanding lies.
I thought that putting my RewriteRule's and RewriteCond's in the httpd.conf would have a global effect across the apache server, but from what I gather now, having a VirtualHost overwrites those settings.
So, I've taken everything out of the httpd.conf and moved them into the VirtualHost's for *.80 and *.443 so that it goes like this.
<VirtualHost *:80>
RewriteEngine On
RewriteRule ^/ssl/(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>
<VirtualHost *:443>
# Plus all the normal ssl extra bits that would be in here too
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/ssl/
RewriteRule ^/(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>
Thanks for the pointers and suggestions.
Cheers,
Russ |
|
Back to top |
|
pawan1475
Joined: 13 Oct 2006 Posts: 2
|
Posted: Fri 13 Oct '06 23:58 Post subject: |
|
|
Hi,
I am having the same problem, i have mod_jk, mod_ssl configured with the apache and Jboss servers and if i use these rules it doesn't forward my Http request to HTTPS. I have these setting in the httpd-ssl.conf file. Am i missing something here.
Thanks in advance.
pawan
Code: |
<VirtualHost *:443>
ServerName 10.88.106.144
ErrorLog C:\apachewin_ssl\logs/error_ssl_log
TransferLog C:\apachewin_ssl\logs/access_ssl_log
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile C:\apachewin_ssl\conf/ssl/server.crt
SSLCertificateKeyFile C:\apachewin_ssl\conf/ssl/server.key
BrowserMatch ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
CustomLog C:\apachewin_ssl/logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
#<Location "/View/pages/secure">
#SSLVerifyClient require
#SSLVerifyDepth 1
#</Location>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/secure/
RewriteRule ^/(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>
<VirtualHost *:80>
ServerName 10.88.106.144
RewriteLog logs/rewrite.log
RewriteLogLevel 9
RewriteEngine on
#RewriteRule /View/pages/secure/(.*)$ https://localhost/View/pages/secure/$1 [R,L]
#RewriteEngine On
RewriteRule ^/secure/(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>
|
|
|
Back to top |
|
|
|
|
|
|