how to deny direct access to index.php and index.php/

Asked

Viewed 50 times

1

Hello, I’m making use of the url friendly, which is working very well, however I want to prohibit access to the archive index.php and index.php/, I want when accessing them to be redirected to the page home.php How do I do this? I have to change something in .htaccess? because the way I put it down here to TRY to solve the problem doesn’t work, see:

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

The above code works right for any other page, login, create account, etc, except when it comes to the index, it seems that it is NOT ALLOWED.

Someone knows what to do?

  • would not be location:home.php instead of location:home

2 answers

1


You can use the Array $_SERVER[]

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

But maybe just the header("location: home.php"); even, solve.

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

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

I don’t know if it works.

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, will be processed everything I had in it and then you will be redirected to the page that was inserted inside the header.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.