Solved

Have website always be https even if they type in http

Posted on 2006-11-17
17
258 Views
Last Modified: 2010-03-04
My company recently got a CA certificate from verisign.  Now we want to secure our entire website.  I have apache 2.0.49, and https works perfectly

I want to know if there is a way, without going and changing every page/link, to just make everything goto the https:// instead of http://
0
Comment
Question by:revo1059
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
  • 2
  • +1
17 Comments
 
LVL 43

Expert Comment

by:ravenpl
ID: 17968462
In Your webroot folder create .htaccess file with following content

RewriteEngine On
ReriteCond %{HTTPS} off
RewriteRule (.*) htps://%{SERVER_NAME}%{REQUEST_URI} [L,R]
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 300 total points
ID: 17968490
Sorry for typos - my wireless kb fails sometimes - have to replace
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

Also note, that it will redirect user externally - user will notice it's redirected. Also if user types
http://web.com and the real server name is www.web.com, it will be redirected to www.web.com - which is SERVER_NAME in our example.

0
 
LVL 1

Author Comment

by:revo1059
ID: 17968535
i tried creating a .htacces and pasted the code you gave me exactly, and it didnt work.  Do i need to do anything else in apache to tell it to read that file?
0
Don't miss ATEN at NAB Show April 24-27!

Visit ATEN at NAB Show to learn how our "Seamlessly Entertaining" solutions deliver fast, precise video streaming without delays for the broadcasting and media environment. ATEN will showcase its 16x16 Modular Matrix Switch (VM1600) and KVM Over IP Solution (KE6900 series).

 
LVL 43

Expert Comment

by:ravenpl
ID: 17968604
> Do i need to do anything else in apache to tell it to read that file?
Usually no, mod_rewrite is usually there and allowed. But in fact You need to be allowed to override FileInfo
Refer http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriteengine http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride
You can also try:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17968621
And the filename is .htaccess not .htacces - just to be sure.
0
 
LVL 1

Author Comment

by:revo1059
ID: 17968636
I know, that was a type-o

I am not very familiar with the httpd.conf file, could you be more specific about where i need to put that allow override
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17968678
Find section
<Directory />
add/change: AllowOverride FileInfo
and restart apache.
But I'm nost sure if that's the problem. Have You tried with the '!on' instead of 'off'
0
 
LVL 1

Author Comment

by:revo1059
ID: 17968713
i looked at my config file.  It looks like i need to change a file in /etc/apache2 called default-server.conf

theres a part that starts with </Directory where i found my server root.  I changed that AllowOverride from none to all.  When i did that, I could get to my webpage anymore.  It said internal server error
0
 
LVL 27

Assisted Solution

by:caterham_www
caterham_www earned 100 total points
ID: 17969483
Just put a

Redirect 301 / https://example.com/

into your <virtualhost> for port 80.
0
 
LVL 1

Author Comment

by:revo1059
ID: 17969606
I don't know what file to put that in.  I have SLES 9 and apache2.  Can you tell me where that would be

I searched /etc/apache2/httpd.conf, /etc/http/httpd.conf and couldn't find anything like <virtualhost>
0
 
LVL 13

Expert Comment

by:rhickmott
ID: 17978002
Try placing it in the <directory> part for your document root.
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17978023
revo1059: You can use Redirect but only if DocumentRoot for Ssl and nonSsl virtualhosts differ.
In such case, just create .htaccess in nonSsl web path with the content rhickmott provided.
0
 
LVL 1

Author Comment

by:revo1059
ID: 17978847
when I tried the .htaccess, i got a error 500... internal server error
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17978924
You need to be allow to override FileInfo. Also rewrite requires the very same override.
Refer http://httpd.apache.org/docs/2.0/mod/mod_alias.html#redirect http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride
You can verist the real error in apache's error log.
0
 
LVL 1

Author Comment

by:revo1059
ID: 17978952
I did a tail -f on the error_log for apache, and got this:

Invalid command 'RewriteEngine', perhaps mis-spelled or defined by a module not included in the server configuration
0
 
LVL 13

Assisted Solution

by:rhickmott
rhickmott earned 100 total points
ID: 17979206
Look for

LoadModule rewrite_module modules/mod_rewrite.so

and remove any # from the start of it
0
 
LVL 1

Author Comment

by:revo1059
ID: 17979547
I have just been told by my boss that he doesn't want https for the homepage.  I guess I will have to come up with another solution.  Thank you for all your advice.
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question