0

I know guys this question has been asked many times but believe me I have tried all the solutions in the other questions without any results.
As mentioned in the title I want all my http requests to be converted into https requests, and I want to use .htaccess file to do this so this is what I have tried so far:

#https redirect
RewriteEngine On
RewriteCond %{HTTPS} !=on    
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]    
RewriteCond %{REQUEST_FILENAME} !-f   
RewriteRule ^(.*)$ app.php [QSA,L]

But this gives me nothing my site is not being redirected from example.com to https://example.com
What am I missing here ?

SlimenTN
  • 3,383
  • 7
  • 31
  • 78
  • Possible duplicate of [How to redirect all HTTP requests to HTTPS](https://stackoverflow.com/questions/4083221/how-to-redirect-all-http-requests-to-https) – Alister Bulman Aug 12 '17 at 10:09
  • @AlisterBulman I know man I said that I have tried all those solution but they did not work, that's why I'm asking ! – SlimenTN Aug 12 '17 at 10:13
  • What do you mean by "without any results"? Certainly _something_ happened. Without you telling us what your actual issue is, what else do you expect as an answer from us than references to the working solutions? – arkascha Aug 12 '17 at 10:16
  • You need to take care that the rewriting module is actually loaded, that it is enabled and usable, that you place your dynamic configuration file in the correct location and that you enabled overriding in your http servers host configuration. We cannot check that for you, only you have access to your system. Oh, and you also should tell us what entries you find in your http servers error log file... – arkascha Aug 12 '17 at 10:17
  • @arkascha literally nothing happend after changing my .htaccess file the site still not being redirected and I have no error in the log file ! – SlimenTN Aug 12 '17 at 10:18
  • Then your rules do not get applied. You need to check the other things I mentioned in my comment above. – arkascha Aug 12 '17 at 10:19
  • @arkascha how can I enable overriding for host configuration ? This one I don't know. – SlimenTN Aug 12 '17 at 10:20
  • Oh, also try replacing `RewriteCond %{HTTPS} !=on` by `RewriteCond %{SERVER_PORT} 80`... It appears that for some distributions of the apache http server `%{HTTPS}` is _not_ always defined as claimed in the documentation. – arkascha Aug 12 '17 at 10:20
  • It is clearly documented that you need to use the `AllowOverride` directive to enable the http server to use your rules in the dynamic configuration file to override the host configuration. That has security reasons which is why it is off by default. In general using such dynamic configuration files is a security issue. Any particular reason why you do not place your rules in the host configuration? – arkascha Aug 12 '17 at 10:22
  • @arkascha I don't know how to do that (place the rules in the host configuration) – SlimenTN Aug 12 '17 at 10:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/151774/discussion-between-arkascha-and-slimen-tunis). – arkascha Aug 12 '17 at 10:25

1 Answers1

3

As worked out in a lengthy communication via chat the issue was that the redirection rules were coded after (below) other internal redirection rules, so never got applied.

Moving the http to https redirection rules up solved the issue.

arkascha
  • 41,620
  • 7
  • 58
  • 90