Search code examples
php.htaccessgodaddy-api

include rule file to along with force https setting in godaddy


I'm using godaddy as hosting in its admin panel I have .htaccess file as shown below

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /core.php [L]
</IfModule>

I made settings to force it to https as below

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%(HTTP-HOST)%{Request-URI} [L,R=301]
</IfModule>

Can any one tell me where to place core.php in rule. My core.php is given as following

<?php
error_reporting( E_ALL );

require_once( "ccioo/Template/class.Page.php" );
header( "Content-Type: text/html; charset=utf-8" );
if ( function_exists( "date_default_timezone_set" ) ) {
    date_default_timezone_set( "Asia/Taipei" );
}
$myPage = new Page();
$myPage->Output();
?>

UPDATE:

So what i want is that either i enter www.myfavouriteweb.com or https://www.myfavouriteweb.com it should redirect to https://www.myfavouriteweb.com


Solution

  • You can use DirectoryIndex from apache

    DirectoryIndex = core.php
    
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%(HTTP-HOST)%{Request-URI} [L,R=301]
    </IfModule>
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ ?original_request=$1 [QSA,L]
    

    In this case you can use $_GET["original_request"] in your core.php If you need the original request

    E.g.

    https://your_site.com/something

    Then in your core.php

    <?php
        if(isset($_GET["original_request"])){
            //here your code
            echo $_GET["original_request"];
        }else{
            //if acces directly to https://your_site.com  (without 'something')
            echo "direct acces";
        }
    ?>
    

    In this example something does not really exist in your server ... It are handled in core.php