Categories
Apache mod-rewrite and htaccess related Articles

Change uppercase URI to lowercase with mod_rewrite (.htaccess)

htaccess uppercase to lowercase

This article explains how to change an uppercase URI string to lowercase with mod_rewrite in an .htaccess file.
With htaccess you can easily convert upper-case characters in URL path to lower-case.
With just a few modifications and by adding a few lines of code you can redirect all of your Upper-case paths to lower-case to make the URL look nice with lower-case characters.
On this article we will provide you a 100% working solution that can just be copied and pasted.

Htaccess redirect uppercase characters in URL path to lowercase

A URL path with upper-case (capital latters) looks something like the following :

/PATH

And a path with lower-case characters looks something as shown below :
/PATH

Assuming your server has the following URL format :

https://example.com/THIS_PATH

You want to redirect URLs like this to its lower-case version

https://example.com/this_path

Here is the RewriteRule you can use in your htaccess to achieve this behaviour :


RewriteEngine on
RewriteCond expr "tolower(%{REQUEST_URI}) =~ m#(.+)/?$#"
RewriteRule [A-Z] %1 [R=301,L]

The rule above searches and converts all Capital letters in URL path string to small letter version. The location where you will put this in an htaccess file is important. If you put this at the bottom or before other rules/directives then it will not be read by server. You will need to put this at the top in your htaccess file.
I hope this article was helpful. Thanks for reading it.

Categories
PHP

Managing MySQL database with PHP using single Object-oriented interface

This article explains how you can access and manipulate MySQL database using MySQLi Object-oriented interface in PHP.
This article covers the following MySQL statements with code examples. The code examples are pasted in the textarea so you can easily copy then edit as per your requirements.

  • CREATE TABLE
  • RENAME TABLE
  • INSERT INTO
  • SELECT

We will use PHP and Mysqli object oriented extension in this tutorial to perform different types of tasks to retrieve , create and
update records on a MySQL database.

Note :-
The codes used here are just for educational purposes and to teach you how to implement a db connection for read and right access. You can copy and paste these codes on your server for testing and learning.

Setting up a secure connection to MySQL database

To connect to MySQL database with our code examples, you must have the following things ready :

  • Your MySQL host name
  • Your MySQL username
  • Your MySQL database password
  • Database name

You will get these informations on your hosting Cpanel. Create a new database and copy the db informations from there.

For testing and learning purposes, create a new directory in your document root and name it as db_project .
Remember that the db_project directory is for learning purposes only and it must be reachable by visiting yoursite.com/db_project/foobar .

Now inside that directory , create a new file named
connection.php with the contents shown below.

connection.php

<?php
//Setting up a secure connection to database
$db_host="localhost";
$db_user="foobar";
$db_pass="123456";
$db_name="my_db";

$conn = new mysqli($db_host,$db_user,$db_pass,$db_name);

// Check the connection
if ($conn -> connect_errno) {
  echo "Could not connect to MySQL: " . $mysqli -> connect_error;
  exit();
}
else {echo "Connected to MySQL database!";}
?>

The connection.php sets up a secure connection with your MySQL database so that you can access the database . You can use this single file to execute multiple Mysqli queries on different pages by including this file.

Add your server informations in this file and test it on your server. If everything is ok you will get a text output “Connected” on your page.

Okay cool, now that you have successfully established the connection with your MySQL server , it’s time to create a table. See the next step below to create a table .

Creating a table on MySQL database

A table on MySQL database can hold multiple columns and rows. In this article , we are going to create a table named MyUsers with 5 unique columns :

  1. ID
  2. username
  3. password
  4. email
  5. reg_date

We will use this table to store user informations.
Create a new file named create_table.php in your db_project directory with the following contents :

create_table.php

<?php

//include the connection file
include "connection.php";


// sql code to create table
//Creating table MyGursts with 5 fields
//----------------------
// ID
//Username
//Password
//Email
//reg_date

$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
username VARCHAR(30) NOT NULL,
password VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)";
//if the query is successful
if ($conn->query($sql) === TRUE) {
  echo "Table MyGuests created successfully";
}
//If something goes wrong

 else {
  echo "Error creating table: " . $conn->error;
}

$conn->close();
?>

The code above creates 5 column in the “MyUsers” table.
The ID column is AUTO_INCREMENT which means that the rows of this column will get incremented by +1 each time a new record is added.
username , password and email has varchar data types with the maximum allowed text and finally the reg_date column is a current time which means the row value of this column will get updated automatically with server date time.

Edit this file if you need to change anything or add more columns and run it on your server . This will create a new table in your MySQL database.

Renaming MySQL table

If you created a new table on MySQL and you want
to change the table name , you can use MySQL RENAME
statement to change the table name.

The code below changes table name from MyUsers to MyNewUsers .

You will only need to use this code if you are not happy with the existing table name and you
want to change it something else.
For learning and testing purpose , create a new file named rename_table.php and put the following contents in that file :



<?php

//include the connection file
include "connection.php";


// sql code to rename table
$sql = "RENAME TABLE MyUsers TO MyNewUsers";
//if the query is successful
if ($conn->query($sql) === TRUE) {
  echo "Table MyUsers renamed successfully";
}
//If something goes wrong

 else {
  echo "Error renaming table: " . $conn->error;
}

$conn->close();
?>

The syntex to change or rename database table is simple and easier to understand.
RENAME TABLE OldName TO NewName
Where OldName is name of your existing table and NewName is the name you want to replace your old table name with.

Adding records to MySQL database with PHP

To add a record to MYSQL db we use the INSERT INTO statement. With this statement we can add a record (row) to db.

add-record.php

<?php
// Include the connection file
include "connection.php";

//Add records to database now
//Adding new records to 3 columns
$user_name="Neha";
$pass="123456";
$email="[email protected]";

$sql = "INSERT INTO MyUsers (username, password, email)
VALUES ('$user_name', '$pass', '$email')";
//If the query is successful
if ($conn->query($sql) === TRUE) {
  echo "New record added successfully";
//If something goes wrong
} else {
  echo "Error: " . $sql . "
" . $conn->error; } $conn->close(); ?>

Select data from MySQL database

To select data from the “MyUsers” table we will use the following code.

Create a new file named select.php in your MySQL test directory and put the following file contents in that file.

select.php

<?php
// Include the db connection file
include "connection.php";

//Select specific columns from MyUsers table
$sql = "SELECT id, username, password, email, reg_date FROM MyUsers";
$result = $conn->query($sql);
// If result rows are more then 0
if ($result->num_rows > 0) {
  // output data of each row in html table

   echo "<table>";
   echo "<tr>";
   echo "<th>ID</th><th>Username</th>
   <th>Password</th>
<th>Email</th>
<th>Registered on</th>
    </tr>";
  while($row = $result->fetch_assoc()) {


    echo "<tr>";
echo '<td>'.$row["id"];
echo '<td>'.$row["username"];
echo '<td>'.$row["password"];
echo '<td>'.$row["email"];
echo '<td>'.$row["reg_date"];
echo "</tr>";

  }
echo "";
} 
// Else print an error
else {
  echo "No results found";
}
$conn->close();
?>

The code above will select all the specific columns from the database.
We have requested to select all the columns from the table. If you just need to get a single column ,ie : username you can then modify the select statement like so :

$sql = "SELECT username FROM MyUsers";

This will now return all the rows for a specific column.

Display database records on a webpage

There are many ways to display MySQL records on a webpage. You can either show the data in tabular format using html table or use any block level elements to show the record. The following is a basic example of showing MySQL records on an HTML webpage. It shows the retrieved data in HTML table element.

<!DOCTYPE html>
<html>
<head>
<title>My db records</title>
</head>
<body>
<!--php code that retrieves records from database-->
<?php
// Include the db connection file
include "connection.php";

//Select specific columns from MyUsers table
$sql = "SELECT id, username, password, email, reg_date FROM MyUsers";
$result = $conn->query($sql);
// If result rows are more then 0
if ($result->num_rows > 0) {
  // output data of each row in html table

   echo "<table>";
   echo "<tr>";
   echo "<th>ID</th><th>Username</th>
   <th>Password</th>
<th>Email</th>
<th>Registered on</th>
    </tr>";
  while($row = $result->fetch_assoc()) {


    echo "<tr>";
echo '<td>'.$row["id"];
echo '<td>'.$row["username"];
echo '<td>'.$row["password"];
echo '<td>'.$row["email"];
echo '<td>'.$row["reg_date"];
echo "</tr>";

  }
echo "";
} 
// Else print an error
else {
  echo "No results found";
}
$conn->close();
?>
</body>
</html>

Categories
Apache mod-rewrite and htaccess related Articles

How to disable directory listing/ directory browsing on Apache server

This article explains how to prevent or block directory listing on Apache web server using an htaccess and server.config files.

What is directory listing or directory browsing

When you request an existent directory on Apache an index file is served but if your directory doesn’t have an index file then Apache shows a list of files and folders. This is called directory listing .
The listing looks something like the following screenshot on Linux

Apache directory listing
By default Apache server shows an index file if it exists in the requested directory but if it doesn’t then the listing of all files and folders is shown.

An index file is the file that has a name starting with index . For example index.html , index.php etc.
If your folder doesn’t have an index file and you want to prevent the listing of files/folders then there are multiple ways to achieve this using a few lines of code in htaccess and server configuration file.
If you don’t have access to the main configuration file then you can use your htaccess. The solutions I am going to provide here work on both contexts.

Prevent directory listing on Apache web server using htaccess

Solution #1

The solution #1 is really simple. If you want to show a 403 error when your directory URL is accessed , you can just put the following line in your htaccess :

Options -Indexes

This two words line does the magic. It tells Apache to show a 403 forbidden error to clients when they request an existent directory . There are also some other ways to handle your direct directory access. See the examples below in the next section.

Block directory listing and set a specific file as index

Solution #2

To prevent directory listing on your server by setting a custom index file, you can use DirectoryIndex directive. This is one of the simplest and the easiest way to hide your files and folders . This directive is part of Apache directory module a module that is especially designed for directories on Apache.
I prefer this solution because it’s very easy to implement and just a single line of code can do the magic.
This directive is available for use in htaccess and server configuration. Since the directory uses same syntax on both contexts , I will show you an htaccess example here.

The following is the line you can use or update your htaccess with :

DirectoryIndex file.php

One liner.. very simple!
The line above instructs your server to show contents of file.php when a browser requests /directory/ .

file.php can be any file of your choice that you want to set as directory index.

An invisible redirection of URLs from /directory/ to file.php is performed by DirectoryIndex . By invisible here I mean you won’t be able to see the URL change in your web browser so the requested URL path /directory/ will show you the contents from file.php .

If you want the URL path to change from /directory/ to /directory/file.php then you can use DirectoryIndex Redirect along with the DirectoryIndex . This directive tells web server to issue an external redirect to index file when a directory is requested.

DirectoryIndexRedirect On

Use it along with DirectoryIndex

DirectoryIndex file.php
DirectoryIndexRedirect on

Note :DirectoryIndexRedirect On issues a temporary redirect from /directory/ to /directory/file.php with a 302 status code which is the default redirect http status code . To make the redirection permanent you can any of the following formats :

With 301 redirect status :

DirectoryIndexRedirect 301

With permanent status :

DirectoryIndexRedirect Permanent

Prevent directory listing/browsing with htaccess

Solution #3

You can also disable directory browsing by using RewriteRule directive in your htaccess file.

Here is the rule you can use in your htaccess :

RewriteEngine on
RewriteRule ^$ /file.php [L]

This works same as the DirectoryIndex method I explained above. This rewrites /directory/ to /file.php .

The most important thing to note here is the pattern ^$ .
In regular expression the pattern ^$ is used to check an empty string and in RewriteRule we use this to match against the current directory or the directory the htaccess file is located in.

For example if your htaccess is located in root then the pattern ^$ is used to match / and the same pattern is used if your htaccess is located in subfolder and you want to match that folder.

See the examples below .

/.htaccess

DirectoryIndex demo.php
DirectoryIndexRedirect 301
RewriteEngine on

This serves the demo.php file when the root directory “/” is direct accessed.

/subfolder/.htaccess

DirectoryIndex demo.php
DirectoryIndexRedirect 301
RewriteEngine on

If the code above is placed in htaccess in subfolder , then a request for /subfolder/ will show you demo.php file instead of showing directory listing.

Block directory listing/browsing using RedirectMatch

Solution #4

It is also possible to show a 403 forbidden error when someone tries to access your directory.

This method is not SEO friendly so I won’t recommend you to use it but if you really want to block direct access to your directories then you can use this.
To prevent directory browsing and display a 403 error ,you can use one of the following methods in your htaccess :

Block direct access to folders using RedirectMatch : This shows a 403 forbidden error when your directory is requested :

RedirectMatch 403 ^/folder/?$

Just replace folder with the name of the folder you want to show a 403 error. For the root folder you can use ^/$ . This does not affect files and subfolders.

Block direct access to folders using RewriteRule : This shows a 403 forbidden error when your directory direct accessed :

RewriteEngine on
RewriteRule ^folder$ - [R=403,L]

For the root folder or the folder your htaccess is located in you can use this pattern ^$ .

I hope this article was helpful . Thank you much for reading it.

Related : Htaccess tutorial for beginners.

Categories
Windows

All you need to know about Windows 11 | Windows 11 features and update

Microsoft is going to release Windows11 this year with some exciting features and a brand new design. Windows11 is the next windows operating system which is the improved version of windows 10.
The new version of Windows has many exciting features and new application icons with rounded and customisable corners.

Home screen of the Windows11
Image credit : Microsoft
Windows 11 home
The new version of Windows is designed to work smoothly on all types of devices from Pen, touch to mouse.


Windows 11 is the successor to the latest windows 10 and it will be available as a free upgrade to windows11 for 10 users through Windows update.
Although , Microsoft hasn’t yet announced the exact date or month of the new windows launch but they have made it clear in the press and on their official site that the new version will be available soon this year .

Windows 11 has new features

Windows 11 is the updated version of Windows 10 . It has all the power and security of its previous version with a new design and fresh look. Windows 11 has new tools, sound and apps. It is designed for all types of devices such as pen, touch and mouse. It’s securer then window 10 .

Windows 11 fresh look video

Windows 11 startup sound

Updating your windows operating system to Windows 11

Windows 10 uses will be able to update their current version to windows 11 without paying anything to Microsoft through the windows update method as they will get a direct link to update their OS. However if you are not using windows version less the 10 and want to direct update to the new version then you will need to buy the Windows11 product key from Microsoft.

Windows11 update methods

System requirements to download windows 11

The following is the minimum system requirements your machine must have in order to install and use the Windows 11 oprating software

    In order to run windows11 smoothly :

  • Your processor must be 64Bit, 1 gigahertz duel or more cores .
    Windows 11 doesn’t work on 32Bit proccesser , you must upgrade your processor to 64Bit before updating to the new version of windows.
  • The minimum RAM required to run Windows11 smoothly is 4GB . If your system RAM is lower then the required format you must upgrade your RAM for the better experience.
  • The minimum storage capacity is 64GB or more.
  • Upgrade your HHD to SSD for better and smoother windows 11 experience.
  • DirectX 12 compatible graphics / WDDM 2.x graphic card
  • The minimum display resolution 720px .
  • Microsoft account and a working internet connection is required to set up windows 11.
Categories
Apache mod-rewrite and htaccess related Articles

Two ways to manipulate URL query strings using RewriteRule in htaccess

Query strings are part of URL that usually appear at the end or before fregment.
A typical query string looks something like the following :

?q=foo&bar=123

Query string in URL starts with a question mark and it contains query key and value parameters.
In the Query String above , q is a key and the foo is its value. Multiple Query key values are separated by an & character.
In this article I am going to show you some useful ways to manipulate query strings using RewriteRule directive. If you want to learn how to match against URL query strings using RewriteRule then you can read further because this post is written especially for URL rewriting beginners. I will show you two working mod_rewrite tricks to manage URL query strings.

Apache mod_rewrite has predefined methods to work with URL query strings

Mod_rewrite beginners often find it complicated to manage or Redirect URL query strings but in fact it’s not that hard. Mod_rewrite has predefined variables to work with it.
The following are the two variables we can use use to manipulate URL query strings :

  • %{QUERY_STRING}
  • %{THE_REQUEST}


%{QUERY_STRING}
is used to match against URL query string. You can use this variable to match against URL query strings.

The following is an an example of how we can test URL query string using RewriteCond directive :

RewriteCond %{QUERY_STRING} ^q=foo&bar=123$ [NC]

The condition above checks a static URL query string that looks something like the followin
?q=foo&bar=123 .
You can use Regular expressions to check query string values dynamically , the following is an example :

RewriteCond %{QUERY_STRING} ^q=.+&bar=.+$ [NC]

The example above matches any values in the query string.


%{THE_REQUEST}
represents the full URL requested by a web browser, you can also use this variable to check URL query string.
If we have the following URL :

example.com/file.php?q=foo
Then we can use the following condition to make sure the URL has the specified Query String

RewriteCond %{THE_REQUEST} \?q=foo\s [NC]

The “\s at the end of the condition pattern above matches a space char and it’s important to use when you are using this variable in RewriteCond as it works like a string boundary.

Redirect URL with Query String

Now you know that we can check query string in two ways on Apache mod_rewrite.
URL redirection with query string is easy .
Suppose we want to redirect our URL with a specific query string to another URL ,

We will learn to redirect :
example.com/file.php?q=foo&n=123
to a different URL , that looks something like :
example.com/demo.php
You can see the second URL is clean and it has no query string , we will use the following rule in our htaccess file for this redirection :

RewriteEngine on
RewriteCond %{QUERY_STRING} ^q=foo&n=123$ [NC]
RewriteRule ^file\.php$ https://example.com/demo.php? [R,L]

One important thing to take note of in the rule above is ? that is at the end of the target URL. This empty question mark is important otherwise the old query string will get appended to the target URL.

The following is the same redirection rule with %{THE_REQUEST}

RewriteEngine on
RewriteCond %{THE_REQUEST} \?q=foo&n=123\s [NC]
RewriteRule ^file\.php$ https://example.com/demo.php? [R,L]

Related articles

Categories
Banking Info

How to create SBI netbanking account – SBI netbanking tutorial

Hello ! Welcome to another tutorial on “Online banking” .
On this tutorial you will learn how to activate netbanking of State Bank of India.
I will show you how you can easily create SBI netbanking account online using your web browser. You don’t need to visit your bank branch to activate your SBI netbanking User ID but instead you can create it yourself using your mobile or desktop device.

What is SBI net banking?

Netbanking by SBI is an online banking platform that allows you to manipulate your bank account without even visiting your bank branch.
With SBI netbanking , you can manage your bank account from any location using an internet connected device.

Benefits of using SBI netbanking

With SBI netbanking you can do the following things :

  • You can manage your bank account online.
  • You can transfer money from your account to others.
  • You can activate or deactivate your Debit/credit card.
  • You can request a new debit card in virtual and physical format online.
  • You can request your account history online
  • You can update Nominee , Email, Phone .
  • You can request passbook/ checkbook online.
  • You can open FD account online.

And more..!
There are also hundreds of other unique features provided by SBI for netbanking users.

How to register for SBI netbanking?

The registration process to start using SBI netbanking is simple and easy to follow. You just need to create your account on the official SBI user registration page.

Before going to the SBI netbanking account creation page, make sure you have the following things ready :

  • Mobile number connected to your SBI bank account.
  • Your SBI account number.
  • CIF number. You can find this number on the first page of your passbook.

To register for SBI netbanking , go to the official registration page of SBI which is on this link https://retail.onlinesbi.com/retail/newuserreg.htm .
SBI netbanking registration

And select the “New user registration” . Click Next.

Fill up all the required fields and hit submit .
SBI registration
That’s it.
Your SBI netbanking user ID will be created immediately . And then you can log in to your SBI netbanking account using the following link https://retail.onlinesbi.com/retail/login.htm .
Sbi net banking login

The registration process is quite simple and easy . You can create your SBI netbanking account with just a few minutes and then you can log into your account to manipulate you SBI bank account online.

I hope this article was simple , easy and was helpful. Thanks so much for reading this.

Categories
Apache mod-rewrite and htaccess related Articles

How to create a custom 404 error page for website using htaccess

In this article I will show how you can create a custom Error page for your website . A custom error page is the one that is shown to your site visitors when they type a broken URL.
If you don’t want to show the dedicated error page then you can create your own page . With the step by step instructions , I will explain how you can easily set up your custom error page with the help of your htaccess file.

First create an error.php file in your web directory

First of all, you need to create a new file that will be served to visitors upon requesting a broken link.

Create a new file named 404-error.php . The file name is just an example here you can change it to whatever name you like.
Add your custom html to the web page . The example error text code is shown below :

Error 404

Sorry, the page you requested couldn't be found.

Save the file in your root web directory and go to the next step which is mentioned below.

Edit your htaccess file to add the custom error code

You will need to add a one single block of code to your htaccess to set up the custom error page redirection.
At the top of your htaccess file, put the following block of code :

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /404-error.php [L]

Make sure the rule is at the top or before other directives in your htaccess.
Don’t try to add this to your WordPress site. The solution won’t work with WordPress.

The code above checks the requested URL path if it doesn’t exist then the request is silently forwarded to the error page. This doesn’t change the URL but makes the internal redirection instead so when your visitors will request a broken link they will see the contents from the custom error file.

If you want to redirection to be visible to client , you can just and a [R] redirect flag to the rule.
Just modify the rule line like the following :

RewriteRule ^ /404-error.php [L,R]

Categories
Apache mod-rewrite and htaccess related Articles

How to remove specific query string from URLs using htaccess

In this article I will show you how we can remove a specific part of URL using RewriteRule directive in an htaccess file.
This article is based on a StackOverflow question asked by an Apache user. I will explain how you can write RewriteRule to trim a specific part of URL.
Let’s first take the real example from the question asked on StackOverflow.
The question poster wanted to remove /?569/ from their original URL which looked something like
https://www.example.com/lang/part1/?569/item1/item2/item3/product.html .
As you can see the URL part the OP wanted to remove starts with a “question mark” ? so it’s part of “URL query string” .
The entire string after ? is part of query string but as the OP asked, we just have to remove the specific segment.

To trim this query string part , we will write a RewriteRule and a Condition in our our htaccess.

We will use the following condition to check the Query String part in the URL :

RewriteCond %{QUERY_STRING} ^569/(.+)$ [NC]

Since we have to trim only the specific part “?569/” we use the pattern ^569/(.+) that matches a query string starting with 569/ and the (.+) matches other characters and saves the match as we will use it in the target URL.
The RewriteRule we will use here is :

RewriteRule ^lang/part1/$ https://www.example.com/lang/part1/%1? [R=301,L]

The pattern of the rule matches the URL path which is /lang/part1/ .
In the Rule’s destination you can see the URL is now “https://www.example.com/lang/part1/%1?” . The %1 is the match from the RewriteCond regex and the ? at the end is there to trim the Old query string so that our final URL could look clean and something like
https://www.example.com/lang/part1/item1/item2/item3/product.html .

The following is the complete Rule to remove the specific part from the mentioned URL :

RewriteEngine on
RewriteCond %{QUERY_STRING} ^569/(.+)$ [NC]
RewriteRule ^lang/part1/$ https://www.example.com/lang/part1/%1? [R=301,L]

Categories
domain

Know the first website in the World

There are billions of web pages on the internet now but none of them existed 30 years ago.

Did you know?
The first website in the world was created 30 years ago and it went live on August 6, 1991.

The first website was created by Tim Berners Lee the inventor of the World Wide Web.
The domain name of the first-ever website was info.cern.ch which contained informations about the World Wide Web and How to create websites.

The first webpage address was http://info.cern.ch/hypertext/WWW/TheProject.html which is still accessable by a web browser.

Screenshot

Screenshot of the first webpage in the World taken on Microsoft edge mobile browser.
The page URL is http://info.cern.ch/hypertext/WWW/TheProject.html
Screenshot of the First webpage in the World

World’s fist live webpage

Categories
Apache mod-rewrite and htaccess related Articles

How to fix it when there are two RewriteRules of identical patterns in htaccess

Are you struggling to fix your RewriteRules with two identical patterns?
In this article I will show you how to fix it when you have two RewriteRules with same patterns in an htaccess file.
I know it’s a bit complicated for people who are new to htaccess to understand why their Rule failed but this article will explain the reason and provide you a working solution.

Rewrite engine reads rules from top to bottom

In an htaccess or server.config files , rules are read from top to bottom . Not just RewriteRule but all directives are read in this order. In your htaccess file the first line is read first.
Suppose, your htaccess file has the following two rules :

RewriteRule ^foo /index.php [L]
RewriteRule ^foot /index.php [L]

As you can see we have two rules of the same pattern, the first rule has a catch-all pattern and it also matches the URL path foot .
The second rule is there created to match a request that starts with foot but for your surprise, the server will only read the first rule wether you type
foo or foot.
The reason behind this is that the both rules have identical patterns.

The ^foo in regex is same as ^foot . It matches anything after the last “o” character.

Fix RewriteRules with identical patterns

You can fix the above rules easily by swapping it. Change the order of the rules ,

RewriteRule ^foot /index.php [L]
RewriteRule ^foo /index.php [L]

Now if you visit foo the engine will read the correct second rule
because the first one doesn’t match it.

Change the form of your URIs

If you have two RewriteRules of the same pattern then the most common issue you will face is Your first rule will be matched while the second one will have no effect.
The following is an example of RewriteRules with identical patterns :

RewriteEngine on
RewriteRule (.*) /index.php [L]
RewriteRule (.*) /index2.php [L]

Only the first rule above will be read by server. To fix this you need to change the form of your URIs. Change the regex of the first pattern to ^first/(.*)$ so that any URIs starting with /first can point to the correct index.php file and other URIs to index2.php.
first is just an example here , you change the pattern to whatever URI you want to set .