Skip to main content

Create Search Engine Friendly URLs using .htaccess

In this post, we will see how to use .htaccess to create search engine friendly URLs. Using .htaccess, mapping dynamic pages to static address is easy and this helps search engines to index the pages fast, effective and strong.

Initially, create a file .htaccess in your favorite editor, use the rewrite rule as below to map dynamic id passing url's to static version. Use the code and create your dynamic pages for search engines spiders

**************************************************************
RewriteEngine on

## Rewrite Rules ##

RewriteRule ^category/([0-9]*)/([0-9]*)/([a-z_]*)$ category.php?id=$1&page_id=$2 [L]
RewriteRule ^category/([^/]*)/([a-z_]*)/([^/]*)$ category.php?r_name=$2&id1=$1


***************************************************************

For eg: Originally the page URL looks like subcategory.php?id=5&page_id=1

Using the above .htaccess code, you can create the URL as

category/5/1/product_name

Here,

RewriteRule ^category/([0-9]*)/([0-9]*)/([a-z_]*)$

^ - Refer to start
Category - creates a folder as mentioned name
/ - Used for virtual partition
[0-9] - Writes single number as folder name
[0-9]* - Writes n numbers as folder name
[a-z_] - Writes single letters as folder name
[a-z_]* - Writes letters as folder name
$ - Refer to end


Additional information:

Your id passing pages might have indexed through some referral and so, you can use the below code to avoid error pages, create a 404pagenotfound.php and add your a message to your visitors to navigate to home page for information’s

*****************************************************************

## Trace Errors
ErrorDocument 404 /404pagenotfound.php


*****************************************************************

Hope you will like the post and its useful :)

Popular posts from this blog

5 SEO Tips to follow in 2022

You would have already knew these SEO tips but you would have ignored or missed out. If you know or not, do consider following and look very close to these, #1 Disavow file Check your site backlinks using your fav SEO tool and find out backlinks which you think is bad and add to the disavow file.    Reference https://www.google.com/webmasters/tools/disavow-links-main #2 Page Speed Improve your page speed for better user experience. This is one of the important ranking signal. Do an analysis & optimize your website with Page speed tool.     Reference https://pagespeed.web.dev/ #3 User Interaction Make sure you provide a good user experience by not completing your web page design. Make it simple and drive the user through an interaction in the form of simple CTA button to get the data. #4 Page layout Shift Every web page should have visual stability. Image or video with unknown dimensions or fonts that loads large then falls back to small or any wired widget o...

Disavow.txt Smart Code Report to Disavow Spammy Or Low-Quality Links

You need to make sure about the links to be disavowed. The main factor is about low-quality & spammy links those points to the site. The process need to be carried out only if you think the links that are to be mentioned are causing issues to your site's online presence. # This Disavow Report was created on Date, year (Today) for domain.com # This report includes links of 2 prior reports submitted on Month Date, Month Date # This report also contains new data added today, Month Date # We have request webmaster to remove our links from their domain. The links from the following domain were cleaned up domain:1xyz.com domain:2xyz.com domain:3xyz.com http://spam.abc.com/article/comments.html # The webmaster did not respond. The links from the following domain were not cleaned up domain:1abc.com domain:2abc.com domain:3abc.com # The below blogspot has differnt ccTLDs. We assume Google will apply disavow to all ccTLDs. domain:xyz.blogspot.com Customize the disa...

Keywords 101 - Types of Keywords and Search Operators

This blog post is about Keywords 101 and it includes information on how keywords works with search, types of keywords and effective easy to search keywords using Google operator. Keywords are of many types that vary to the individual human behavior. Keywords are not created they are formed. What are Keywords? Keywords are words that are used to search information in Search Engines that refers to a specific topic. Keywords can vary like Singular Keywords, Plural keywords, Strong & Weak keywords, Global & Local keywords, Misspelled keywords, Seasonal keywords and Long tail keywords. How Keywords work? When you search for information using a Keyword[1], the Search Engine looks for all the indexed pages in the database contacting the specific word or words (Called as keywords). If you try for a Keyword 'SEO and SMO' then the search engine will look for the pages that contain the words 'SEO and SMO'. Despite you will see topics that relates to only SEO and...