-2

this is the htaccess code for PHP MVC Program



RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ index.php?url=$1 [L]

! Please read properly !

what i want is :

  • Force https
  • then go to index.php file and send url data

! Please read properly !

i added new htaccess file like this



RewriteEngine On

RewriteCond %{HTTP:X-Forwarded-Proto} !https

RewriteCond %{HTTPS} off

RewriteCond %{HTTP:CF-Visitor} !{"scheme":"https"}

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

in the parent dir

but, it still doesnt make force HTTPS

please answer this and

Read properly

sorry for my bad english

De Heger
  • 1
  • 2
  • Try this .... put it on top of htaccess ```RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]``` – Anant V Apr 28 '23 at 05:01
  • Multiple RewriteConds are joined with an implicit AND, unless you use the `OR` flag. I somehow doubt that all three of those conditions you are checking there are fulfilled at the same time, usually the information whether HTTPS was used is provided in one of those ways, but not all of them. – CBroe Apr 28 '23 at 06:31
  • @CBroe thanks, now i can save some line in htaccess. – De Heger Apr 28 '23 at 21:56

2 Answers2

0
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
-1

thanks all, i found the answer, i dont think this is 100% accurate. so please correct me if im wrong :)

just do this on .htaccess file

#Turn On RewriteEngine
RewriteEngine On
#If the HTTPS is off
RewriteCond %{HTTPS} off
#Redirect to HTTPS
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#%{HTTP_HOST} is equal to the host domain 

#if the request url is a file ignore it
RewriteCond %{REQUEST_FILENAME} !-d
#if the request url is a dir, ignore it
RewriteCond %{REQUEST_FILENAME} !-f
#whatever was typed from start to end, move to index.php and send whatever the user has typed. and dont apply any RewriteRule after this
RewriteRule ^(.*)$ index.php?url=$1 [END]
  • Force HTTPS ✓
  • go to index, and send the url data ✓

for sources of information about RewriteEngine is Here

This is weird, i answer my own question.

im sorry if my explanation is difficult to understand :)

De Heger
  • 1
  • 2