Allow only https and not http on centOS

Hi,

I have centOS on my machine. I want to implement ssl on centOS for my appliation.

I have successfully implemented ssl . Now my site is accessible by using https.
But when I try to access the site by http. It allows the http also.

I want the site should be accessible by using https and not http.

Can any one help me please what other changes need to do for accessing the site by https only?

Thanks.

You can use mod_rewrite to take any non-SSL requests and redirect them to the same location with SSL:

RewriteEngine on
RewriteCond %{SERVER_PORT} !443 
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

Thanks Dan,

Do I need to use .htaccess for this?

Apache configuration directives can be placed in the httpd.conf file, any file included by httpd.conf, or in a .htaccess file within the site’s document root.

ok.
But where do I place this in httpd.conf. at the bottom of the file. or anywhere I can put the above line.

One more doubt
I have xampp on my centos
so if I run the command ‘/opt/lampp/lampp startssl’, then also it is necessary to put the above rule in httpd.conf file?

Please help me.

They can be in the httpd.conf file in a <Directory> block corresponding to the document root, a <VirtualHost> block corresponding to the virtual host, or a .htaccess file.

You need the rule no matter what command you use, if you want to redirect people accessing the site without SSL.

To do so,
mod_rewrite module should be enabled. right?

LoadModule rewrite_module modules/mod_rewrite.so

Also <virtualhost> block is not in the httpd.conf file.
Making the changes in <Directory> block is enough?

Thanks a lot Dan

You saved my life.

It worked.