.htaccess

How to make SEO friendly url using htaccess

In previous tutorial we learned about what is .htaccess . In this tutorial I will explain how to make SEO friendly url using htaccess.
Ex 1 :
https://phpgurukul.com/books.php?bookName=php  using  htaccess  url will be written like this https://phpgurukul.com/php
You can do this using code given below in htaccess file :

RewriteEngine On
RewriteRule ^([^/\.]+)/?$ books.php?bookName=$1

Ex 2 :
https://phpgurukul.com/books.php?bookName=php&&chapter=array   using  htaccess  url will be written like
https://phpgurukul.com/php/array
You can get by using code in htaccess file given below :

RewriteEngine On
RewriteRule ^([^/\.]+)/([^/\.]+)?$ books.php?bookName=$1&chapter=$2

Ex 3 :
https://phpgurukul.com/books.php?bookName=2&&chapter=5 using  htaccess  url will be written like
https://phpgurukul.com/php/2/array/5
You can get by using code in htaccess file given below :

RewriteEngine on
RewriteRule product/catName/(.*)/bookName/(.*)/books.php?bookName=$1&chapter=$2

we can handle this url in other way like this https://phpgurukul.com/books-php-2-array-5.html

RewriteEngine on
RewriteRule product-catName-(.*)-bookName-(.*)\.html$ books.php?bookName=$1&chapter=$2

 

Recommended Tutorials for you


Related posts

What is .htaccess

Anuj Kumar

How to create custom error page using .htaccess

Anuj Kumar

How to redirect website HTTP to HTTPS using .htaccess

Anuj Kumar

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.