Apache Htaccess HTTP Server Tutorial

Apache Htaccess HTTP Server Tutorial

Today, We want to share with you Apache Htaccess HTTP Server Tutorial.
In this post we will show you Apache .htaccess file – Examples and Common Uses | htacces Download, hear for Apache Htaccess Programming Tutorial And Examples we will give you demo and example for implement.
In this post, we will learn about What is .htaccess? – Apache .htaccess Guide, Tutorials & Examples with an example.

How to Create a simple .htaccess File?

Simple Open any text editor Like as a (Notepad++) application and file save (.htaccess) as with .htaccess name and simple enable mod_rewrite extension in change to php.ini file in Apache (linux server) Web Server configurations.

Simple Making .htaccess file

|htdocs
|-Images
|-js
|-index.php
|-.htaccess

Domain Redirection(How do I redirect one domain to another domain name? – SiteGround)

 .htacces code for redirecting Pakainfo.com.com to www.Pakainfo.com.com

Solution

RewriteCond %{HTTP_HOST} ^Pakainfo.com.com
RewriteRule (.*) http://www.Pakainfo.com.com/$1 [R=301,L]

Download

Sub Domain Redirection(How to redirect a subdomain to another page)

 Sub domain redirection mapping to folder. Here http://www.Pakainfo.com.com is connecting to web_folder_name folder. 

Solution 1

RewriteCond %{HTTP_HOST} ^www\.Pakainfo.com\.com$
RewriteCond %{REQUEST_URI} !^/web_folder_name/
RewriteRule (.*) /web_folder_name/$1

Solution 2

Here http://subdomain.Pakainfo.com.com is connecting to subweb_folder_name folder.

RewriteCond %{HTTP_HOST} ^subdomain\.Pakainfo.com\.com$
RewriteCond %{REQUEST_URI} !^/subweb_folder_name/
RewriteRule (.*) /subweb_folder_name/$1

Download

Old Domain Redirection(Redirect an Old Domain to a New Domain with .htaccess)

demo w3free.com is now redirecting to pakainfo.com

Solution

RewriteCond %{HTTP_HOST} ^Pakainfo.com
RewriteRule (.*) http://www.live24.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.pakainfo\.com
RewriteRule (.*) http://www.Pakainfo.com/$1 [R=301,L]

Download

Disable directory Listing (How to Prevent a Directory Listing of Your Website with .htaccess)

# Disable Directory Browsing
Options All -Indexes

Download

Simple Hide .php(filename) extension with URL Rewriting (how to remove php extension from url without htaccess)

RewriteEngine on
RewriteRule ^(.*)\$ $1.php 

Download

Convert index.php to index.html using htacces

RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php 

Download

Redirecting www URL to non www URL

  
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.Pakainfo.com
RewriteRule (.*) https://www.pakainfo.com/$1 [R=301,L]

Download

Friendly URLs

Friendly URLs (userfriends seo Friendly)help in search engine rankings.

aboutus URL Examples

https://www.pakainfo.com/aboutus.php?userparamname=itking
to
https://www.pakainfo.com/itking

Solution

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

Download

msgstatus URL Examples

https://www.pakainfo.com/msgstatus.php?msg_user_name=itking
to
https://www.pakainfo.com/msgstatus/itking

Solution

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

Download

userfriends URL Examples

https://www.pakainfo.com/userfriends.php?userparamname=itking
to
https://www.pakainfo.com/userfriends/itking

Solution

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

Download

userfriends URL with Two Parameters (htaccess rewrite url get parameters)

https://www.pakainfo.com/userfriends.php?userparamname=itking&page=2
to
https://www.pakainfo.com/userfriends/itking/2

Solution

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

Download

Hiding File Extension(How to remove .php, .html, .htm extensions with .htaccess)

http://www.Pakainfo.com.com/index.html
to
http://www.Pakainfo.com.com/index

Solution

 RewriteRule ^([^/.]+)/?$ $1.html

Download

Leave a Comment