skip to Main Content

this is the htaccess code for PHP MVC



RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

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

what i want is :

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

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

sorry for my bad english

2

Answers


  1. Chosen as BEST ANSWER

    thanks all, i found the answer, i dont know if this work or not, 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
    #do this
    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 :)


  2. RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search