how to prohibit direct access to index.php file and index.php /

1
Hello, I am using url friendly, which is working very well, however I want to prohibit access to the file index.php and index.php/ , I want that when accessing them it is redirected to the page home.php How do I do this? Do I have to change something in .htaccess ? because the way I put down here to TRY solve the problem does not work, see:

$pag = ($_GET['pag']));
if ($pag == 'index.php' || $pag =='index.php/')
{
   header("location: home");
}

The code above works perfectly for any other page, login, create-account, etc., less when it comes to index, it seems that it is not PERMITTED.

Does anyone know what to do?

    
asked by anonymous 19.12.2018 / 19:09

2 answers

1

You can use Array $_SERVER[]

<?php
$URL= "$_SERVER[REQUEST_URI]";
if ($URL === "/index.php" || "/index.php/") {
    header("location: home.php");
}
?>

But maybe only the% with% of the same, solve.

And with a search on the internet I found this pro .htaccess:

RedirectMatch ^/$ http://siteDaMiriam/home.php

I do not know if it works.

    
19.12.2018 / 19:53
0

You can put at the end of your index.php and index.php / the following:

<?php
header('location:home.php');
?>

With this every time someone enters this page, everything I had in it will be processed and then you will be redirected to the page that was inserted inside the header .

    
19.12.2018 / 19:23