6+ Most Wanted SEO Clean URLs Tricks Using Htaccess

How To Use  Htaccess File
6+ Most Wanted SEO Clean URLs Tricks using Htaccess
Hello readers in this article we will get some information about htaccess file and how to use it, The basically htaccess file is a configuration file that allows for decentralized management of web servers. Let me tell you in human language htaccess is used for rewriting urls and domain, also for security. After reading this post you will be able to make a clean url for SEO and rewriting URLs for profiles or messages like social media sites, let's focus on these main things:

  • Making Htaccess File,
  • Enabling  Mod_Rewrite Extension In PHP.ini  
  • Disable directory Listing
  • Error Page
  • SEO  Friendly Clean URLs 
  • URLs For Profile Like Facebook

How to Create a .htaccess File

Open your notepad or what editor you like and Save As .htaccess, not like myfile.htaccess just .htaccess
6+ Most Wanted SEO Clean URLs Tricks Using Htaccess

How to Enable Mod_Rewrite Extension In PHP.ini 

If you are using hosting then hosting site have already enabled Mod_rewrite if not you can ask your hosting provider allow you Enable it. I'm using xampp so go to xampp\apache\conf and there will be an httpd. conf file, open it and find Mod_Rewrite tip: use search by pressing Ctrl+f remove the “#” at the starting of the line, “#” represents that line is commented

How to Prevent a Directory Listing of Your Website

By default everyone can see your folders in your website directory to prevent directory from Listing all you need to do is add a single line of code in your htaccess file to site root folder

6+ Most Wanted SEO Clean URLs Tricks Using Htaccess

# Disable Directory Browsing
Options All -Indexes
after adding htaccess in stie root folder

How To Redirect Http Errors To Error Page

You can redirect errors to custom page or change the default error message also Redirect to a script. This will allow when user request a page that doesn't exist on the server
  • Redirect To Custom Error Page
  • Change The Default Error Messages
  • Redirect To Script
  • Redirecting To Custom Error Page
Redirecting To Custom Error Page
# Disable Directory Browsing
Options All -Indexes
ErrorDocument 400 /YourSitefolder/errorpage.html
ErrorDocument 401 /YourSitefolder/errorpage.html
ErrorDocument 403 /YourSitefolder/errorpage.html
ErrorDocument 404 /YourSitefolder/errorpage.html
ErrorDocument 500 /YourSitefolder/errorpage.html 
After Appling
6+ Most Wanted SEO Clean URLs Tricks Using Htaccess

Changing Default Error Messages

# Disable Directory Browsing
Options All -Indexes
ErrorDocument 400 "Ooops - Bad request!
ErrorDocument 401 "first log on with a valid user ID and password.
ErrorDocument 403 "Don't be smart
ErrorDocument 404 "Page is Not Found 
ErrorDocument 500 "Server gone for Shopping..
6+ Most Wanted SEO Clean URLs Tricks Using Htaccess

Redirecting To  Script

ErrorDocument 400 YourSiteNamehere/redirection.php
ErrorDocument 401 YourSIteNamehere/authentication.php
ErrorDocument 403 YourSiteNamehere/checkinguser.php
ErrorDocument 404 /cgi-bin/not_found.pl
ErrorDocument 500 /cgi-bin/server_error.pl

Making SEO Friendly URLs

Friendly Urls are important for search engines I'll explain how to rewrite URLs with htaccess  see below :

 Original URL:
6+ Most Wanted SEO Clean URLs Tricks Using Htaccess

6+ Most Wanted SEO Clean URLs Tricks Using Htaccess
Screenshots From my recent cms

Original URL:
http://mysite.com/post.php?post_title=how to make
Rewriting URL

RewriteEngine On
RewriteRule ^([a-zA-Z0-9-/]+).html$ post.php?post_title=$1
RewriteRule ^([a-zA-Z0-9-/]+).html/$ post.php?post_title=$1

Original URL:
Rewriting URL

RewriteEngine On

RewriteRule ^([a-zA-Z0-9_-]+)/\followers$ followers.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/\following$ following.php?id=$1
Hiding File Extension

RewriteRule ^friends/([a-zA-Z0-9_-]+)/([0-9]+)$ friends.php?username=$1&page=$2
RewriteRule ^friends/([a-zA-Z0-9_-]+)/([0-9]+)/$ friends.php?username=$1&page=$2

How To Make Profile Url Like Facebok

Making urls like facebook with htaccess :

Original URL:
Rewriting URL

RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?username=$1
Original URL:
Rewriting URL

RewriteRule ^friends/([a-zA-Z0-9_-]+)$ friends.php?username=$1
RewriteRule ^friends/([a-zA-Z0-9_-]+)/$ friends.php?username=$1

Original URL:
Rewriting URL

RewriteRule ^messages/([a-zA-Z0-9_-]+)$ messages.php?message=$1
RewriteRule ^messages/([a-zA-Z0-9_-]+)/$ messages.php?message=$1


Post a Comment