How to make pretty URL in PHP using .htaccess
Hello Everyone,
Here in this tutorial, you will learn How to make a pretty URL in PHP using .htaccess. and the Htaccess file tutorial and tips. using htaccess you can configure and redirect the apache web server file system. if you are using an Nginx server htaccess won’t work in your server, you have to use Nginx config for that. This tutorial will teach you how to create pretty URLs( friendly URLs) with your website.
.htaccess file will be in hidden format please turn on settings to show hidden files to view this file
How to create a .htaccess file
Open your text editor and save the file with the .htaccess extension (yes, you don’t need to name it anything .. its only needed the extension )
How to Disable Directory Listing using .htaccess
if you want to disable showing all files in the folder include the following code into your htaccess file
# Disable Directory Browsing Options All -Indexes
How to Do Domain Redirection using .htaccess
here is the htaccess code for redirect your yourwebsite.com to www.yourwebsite.com
RewriteEngine On RewriteCond %{HTTP_HOST} ^yourwebsite.com RewriteRule (.*) https://www.yourwebsite.com/$1 [R=301,L]
Okay, let’s talk about Friendly URLs now – Friendly URLs knows as Pretty URLs will help in search engine rankings.
let’s make one for our blog
How to make Pretty/ Friendly Url using htaccess
Think your URL is https://website.com/blog.php?link=my-first-post Looks not great right. so let’s make it something like https://website.com/my-first-post this , Yes looks great. we can make it with 2 lines of code in htaccess and the code the following
RewriteEngine On RewriteRule ^([a-zA-Z0-9_-]+)$ blog.php?link=$1 RewriteRule ^([a-zA-Z0-9_-]+)/$ blog.php?link=$1
How to Hide File Extension using htaccess
Now we are going to hide some of our file extensions with htaccess.
want to know how? we are going to hide .html from the end https://website.com/about.php to https://website.com/about
wants to know how ? here is the code
RewriteEngine On RewriteRule ^([^/.]+)/?$ $1.php #for php files
you can use the same for HTML files too
RewriteEngine On RewriteRule ^([^/.]+)/?$ $1.html
Hope this helps.
Post Your Questions on our forum
Post a question on Forum
Share with your friends:
How to Compress Image using PHP
In this tutorial we are going to talk about how to Compress Images using PHP, You can reduce the image […]
13 October, 2021
How to backup and download Database using PHP
Learn How to backup and download Database using PHP. Most of the time we develop some applications, the most important […]
8 October, 2021
How to make a Zip file using PHP
Hello Everyone In this tutorial, we are going to make a zip file using PHP. and we also unzip the […]
How to make pretty URL in PHP using .htaccess
Hello Everyone, Here in this tutorial, you will learn How to make a pretty URL in PHP using .htaccess. and […]
18 September, 2021
Digital Marketing Toolkit
Get Free Access to Digital Marketing Toolkit. You can use all our tools without any limits
Get Free Access Now