2

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

Mani
  • 2,391
  • 5
  • 37
  • 81
  • Are you wanting to force HTTPS? If not, this question isn't really clear. – Adam Mar 04 '19 at 14:32
  • @Adam yes I do want to force https – Mani Mar 04 '19 at 14:36
  • Is some like this what you want ? : `RewriteRule ^(.*)$ https://%(HTTP-HOST)/core.php [L,R=301]` – MTK Mar 04 '19 at 14:54
  • @MTK i try it . – Mani Mar 04 '19 at 14:54
  • @MTK It is taking some time. but see my updated section of question plz. thank you – Mani Mar 04 '19 at 15:00
  • Ok. In this case your original `RewriteRule ^(.*)$ https://%(HTTP-HOST)%{Request-URI} [L,R=301]` must working. But the question is you have one active SSL certificate for your host ? Because if not can't work – MTK Mar 04 '19 at 15:10
  • @MTK If you see i have a core.php too. how to include that in my final htaccess – Mani Mar 04 '19 at 15:13
  • So if I understand you need to redirect all your traffic to `https://your_site/core.php`. Is true ? – MTK Mar 04 '19 at 15:16

1 Answers1

0

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

MTK
  • 3,300
  • 2
  • 33
  • 49
  • Don't forget ... `core.php` in this example must be on the root of your http_folder ... or you can change relative path ... E.g ´/your_folder/core.php´ ... remember ... this is relative to your public_http folder – MTK Mar 04 '19 at 15:49
  • blank page ... and sometimes says 'this page isn't working' – Mani Mar 04 '19 at 15:50
  • See my updated answer. You need (for testing) to replace your original `core.php` ... with mi example – MTK Mar 04 '19 at 15:55
  • should i put the echo too ? – Mani Mar 04 '19 at 15:55
  • Yes the eco is only for testing ... first you need to test if it work ok ... after that ... you can replace with code you want. But first you need to be sure if it working – MTK Mar 04 '19 at 15:57
  • it prints 'direct acces' in blank white page – Mani Mar 04 '19 at 15:57
  • SO IT WORK AS ESPECTED :) – MTK Mar 04 '19 at 15:58
  • Now you need to add your code ... instead echo ... you can put your original ... code – MTK Mar 04 '19 at 15:59
  • you mean i should put all the code of if statement in else too ? or just in the else statement ? – Mani Mar 04 '19 at 16:00
  • Not if ... to else ... Your original code from your original `core.php` But ... you need also to understand what are you doing , because until here ... I can help – MTK Mar 04 '19 at 16:02
  • This page isn’t working www.site.com sent an invalid response.ERR_INVALID_REDIRECT – Mani Mar 04 '19 at 16:05
  • So in this case `ERR_INVALID_REDIRECT ` is a bug from your libary or template you use ... because withowt it work – MTK Mar 04 '19 at 16:19
  • if your template is `wordpress` you can see: https://stackoverflow.com/questions/49165726/wordpress-social-login-plugin-returning-err-invalid-redirect-having-nginx-for-ho – MTK Mar 04 '19 at 16:20
  • or try to search on google or stackoverflow `err_invalid_redirect your_template_library_or_plugin_name` – MTK Mar 04 '19 at 16:23
  • 1
    thanks @MTK. your answer and instructions were helpful in finding the real answer. accepting this because it lead to actual answer. – Mani Mar 04 '19 at 20:09