php - overlapping htaccess commands?

one text

Solution:

I am sure after this my example you will get exact idea in detail about that... just copy & try to understand about this...

create one Project Folder, then Create one .htaccess file , user.php, index.php, test.php

then copy below code... in .htaccess file

RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
RewriteRule ^test?$ test.php
RewriteRule ^user?$ user.php
RewriteRule ^user/([0-9]+)$ user.php?id=$1
RewriteRule ^game/(1)? http://triviamaker.com [R=301,L]

in user.php file

<?php 
if(isset($_GET['id'])){
    echo "User Id :".$_GET['id'];
}else{
    echo "<h3>Opps write localhost/user/anynumber</h3>";
}
?>

in index.php file

<?php 
echo "Hello World";
?>

in test.php file

<?php
echo $temp = $_GET['land'];
echo $temp = $_SERVER['QUERY_STRING'];
    if($temp == "1" || $temp == "land=1"){
        header('Location: https://example.com');
    }else if($temp == "2" || $temp == "land=2"){
        header('Location: https://gmail.com');
    }else if($temp == "3" || $temp == "land=3"){
        header('Location: https://apple.com');
    }else if($temp == "4" || $temp == "land=4"){
        header('Location: user/2');
    }
?>

Now Run this files:

  1. localhost/your_project_folder_name/
  2. localhost/_your_project_folder_name/user
  3. localhost/_your_project_folder_name/user.php

& also run with parameter like this

  1. localhost/_your_project_folder_name/user/1
  2. localhost/_your_project_folder_name/user/2
  3. localhost/_your_project_folder_name/test?2
  4. localhost/_your_project_folder_name/test?3
  5. localhost/_your_project_folder_name/game/1

I hope with this example You can understand different different scenarios easily... Thank You

Source