• 11
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I am trying to redirect all requests within a directory on a server to https. I have tried the following in a separate config (within the config.d directory), and in an .htaccess file. Neither work, but cause no errors.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

When I tried in a config file the above was within a block.

EDIT
Here is my code in the config file:

<Directory "/var/www/html/ssl_dir/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    <RequireAny>
        Require ip xx.xx.xx.0/24
        Require ip ::1
    </RequireAny>
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{HTTPS} !=on
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    </IfModule>  
</Directory>

Almost there!

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

https://stackoverflow.com/questions/3307025/force-https-on-certain-urls-and-force-http-for-all-others

My first answer mistakenly used SERVER_NAME, which does not necessarily equal HTTP_HOST. The server name can be anything and very different from the domain name used to access it.

  • 0
Reply Report

Trending Tags