3

I want to redirect all of my HTTP requests to my HTTPS (SSL) protocol. Please guys this is not a duplicate. I have already tried every question found on SO which indicate such question but none of them worked. I tried everything I found on the internet but still cannot figure out what the problem is. May be somewhere something has to be enabled or something like that.

I want to redirect from my httpd.conf file not from .htaccess because this is what suggested by Apache Org. My current Redirection Rule is

<VirtualHost *:80> 
    ServerName www.example.com
    Redirect / https://www.example.com/
</VirtualHost > 
<VirtualHost *:443>
    ServerName www.example.com
</VirtualHost >

I am making all of these changes in my httpd.conf file located in /etc/httpd/conf/httpd.conf

After every change, I also restart my server with following /etc/init.d/httpd restart or service httpd restart

I also tried following

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/%$1 [R,L]

But still when I visit my site like www.example.com, I am not redirected to https://www.example.com.

I have a VPS Server so has enough access to my machine to enable or disable something.

2
  • have you tried everything in this question? (and make sure you restart apache) Commented Mar 28, 2016 at 7:45
  • @DevDonkey Yes Sir. I already tried everything in that question. Infact I learned from that how to redirect from Http to Https Commented Mar 28, 2016 at 7:46

2 Answers 2

4

Try with:

RewriteEngine on 
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R] 
Sign up to request clarification or add additional context in comments.

Comments

0

This working for me:

 # Force SSL
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP:X-Forwarded-Proto} =http
  RewriteCond %{HTTP_HOST} ^example.com
  RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.