SlideShare a Scribd company logo
2
Most read
11/23/13 Htaccess File Tutorial and Tips.
www.9lessons.info/2013/11/htaccess-file-tutorial-and-tips.html 1/4
After posting Understanding of Regular Expression article most of my readers are expectingAfter posting Understanding of Regular Expression article most of my readers are expecting
.htaccess basics, and I did not find any useful article on Google first page results. Specially I.htaccess basics, and I did not find any useful article on Google first page results. Specially I
love to writelove to write.htaccess.htaccess file, using this you can easily configure and redirect Apache Web Serverfile, using this you can easily configure and redirect Apache Web Server
file system. This post will explain you how to create friendly URLs, sub domain directory re-file system. This post will explain you how to create friendly URLs, sub domain directory re-
directions and many more.directions and many more.
Download Script Live Demo
Note: .htaccess file will be in hidden format, please change your folder and file settings to view this
file.
How to Create a .htaccess File?
Open any text editor application and file save as with .htaccess name and
enablemod_rewrite extension in php.ini file in Apache Web Server configurations.
Default directory Listing
11/23/13 Htaccess File Tutorial and Tips.
www.9lessons.info/2013/11/htaccess-file-tutorial-and-tips.html 2/4
Disable directory Listing
If you want to disable folder files listing, include following code.
# Disable Directory Browsing
Options All -Indexes
Error Pages
Here error page is redirecting to error.html.
errorDocument 400 http://www.youwebsite.com/error.html
errorDocument 401 http://www.youwebsite.com/error.html
errorDocument 404 http://www.youwebsite.com/error.html
errorDocument 500 http://www.youwebsite.com/error.html
RewriteEngine On it is turn on Rewrite Rules in Apache Server. if you want to turn off, just change
the value to off.
RewriteEngine on
11/23/13 Htaccess File Tutorial and Tips.
www.9lessons.info/2013/11/htaccess-file-tutorial-and-tips.html 3/4
Domain Redirection
.htacces code for redirecting yourwebsite.com to www.yourwebsite.com
RewriteCond %{HTTP_HOST} ^yourwebsite.com
RewriteRule (.*) http://www.yourwebsite.com/$1 [R=301,L]
Sub Domain Redirection
Sub domain redirection mapping to folder. Here http://www.yourwebsite.com is connecting
to website_folder folder.
RewriteCond %{HTTP_HOST} ^www.yourwebsite.com$
RewriteCond %{REQUEST_URI} !^/website_folder/
RewriteRule (.*) /website_folder/$1
Here http://subdomain.yourwebsite.com is connecting to subdomain_folderfolder.
RewriteCond %{HTTP_HOST} ^subdomain.yourwebsite.com$
RewriteCond %{REQUEST_URI} !^/subdomain_folder/
RewriteRule (.*) /subdomain_folder/$1
Htaccess File Inside The Folder.
Old Domain Redirection
htaccess code for redirecting old domain(abc.com) to new domain(xyz.com). Live
demo fglogin.com is now redirecting to oauthlogin.com
RewriteCond %{HTTP_HOST} ^abc.com
RewriteRule (.*) http://www.xyz.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.abc.com
RewriteRule (.*) http://www.abc.com/$1 [R=301,L]
Friendly URLs
Friendly/Pretty URLs help in search engine rankings.
Profile URL
Profile parameter allows [a-zA-Z0-9_-] these inputs. More help read Understanding Regular
Expression
http://labs.9lessons.info/profile.php?username=srinivas
to
http://labs.9lessons.info/srinivas
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?username=$1
11/23/13 Htaccess File Tutorial and Tips.
www.9lessons.info/2013/11/htaccess-file-tutorial-and-tips.html 4/4
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?username=$1
Messages URL
http://labs.9lessons.info/messages.php?message_username=srinivas
to
http://labs.9lessons.info/messages/srinivas
RewriteRule ^messages/([a-zA-Z0-9_-]+)$ messages.php?
message_username=$1
RewriteRule ^messages/([a-zA-Z0-9_-]+)/$ messages.php?
message_username=$1
Friends URL
http://labs.9lessons.info/friends.php?username=srinivas
to
http://labs.9lessons.info/friends/srinivas
RewriteRule ^friends/([a-zA-Z0-9_-]+)$ friends.php?username=$1
RewriteRule ^friends/([a-zA-Z0-9_-]+)/$ friends.php?username=$1
Friends URL with Two Parameters
Here the first parameter allows [a-zA-Z0-9_-] and second parameter allows only number [0-9]
http://labs.9lessons.info/friends.php?username=srinivas&page=2
to
http://labs.9lessons.info/friends/srinivas/2
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
Hiding File Extension
http://www.yourwebsite.com/index.html
to
http://www.yourwebsite.com/index
RewriteRule ^([^/.]+)/?$ $1.html

More Related Content

PDF
Technical SEO: .htaccess & 301 Redirects
PDF
PHP Includes
PPTX
WordPress Ann Arbor: Redirects and Robots for Accurate Analytics Results
PPTX
asp.net Webconfiguration
PPT
Drupal Installation & Configuration
ODP
Php File Upload
PPTX
crtical points for customizing Joomla templates
PDF
Deployment with ExpressionEngine
Technical SEO: .htaccess & 301 Redirects
PHP Includes
WordPress Ann Arbor: Redirects and Robots for Accurate Analytics Results
asp.net Webconfiguration
Drupal Installation & Configuration
Php File Upload
crtical points for customizing Joomla templates
Deployment with ExpressionEngine

What's hot (20)

PDF
Apache Server Tutorial
PDF
Making Your Own URL Shortening Service
PDF
puissance-2roue
PPT
Apache
PPTX
Uploading a file with php
PPT
Local Drupal MultiSite Set-up
PPTX
PPT
Apache Web Server Setup 3
PPT
Apache Ppt
KEY
Switching search to SOLR
PPT
Apache Web Server Setup 1
PPT
File Upload
PPTX
CIT499 Semester Project
PDF
How to use_000webhost
PPT
How to Hack Website using SQL Injection Attack
PPTX
PHP Hypertext Preprocessor
PDF
Getting Under the Hood - WordPress File & Directory Structure
PPT
Apache Web Server Setup 4
PDF
Defeating Cross-Site Scripting with Content Security Policy
Apache Server Tutorial
Making Your Own URL Shortening Service
puissance-2roue
Apache
Uploading a file with php
Local Drupal MultiSite Set-up
Apache Web Server Setup 3
Apache Ppt
Switching search to SOLR
Apache Web Server Setup 1
File Upload
CIT499 Semester Project
How to use_000webhost
How to Hack Website using SQL Injection Attack
PHP Hypertext Preprocessor
Getting Under the Hood - WordPress File & Directory Structure
Apache Web Server Setup 4
Defeating Cross-Site Scripting with Content Security Policy
Ad

Similar to Htaccess file tutorial and tips (20)

PDF
PDF
testing pdf doc
PPT
Comparative Development Methodologies
PPTX
.htaccess
KEY
mod_rewrite bootcamp, Ohio LInux 2011
KEY
URL Mapping, with and without mod_rewrite
PPTX
Part 2 of Advanced SEO tips for Exponent CMS
KEY
mod_rewrite
PPT
Apache mod_rewrite
PDF
mod_rewrite
PPT
Google Bot Herding, PageRank Sculpting and Manipulation
PDF
mod_rewrite
ODP
Learn how to use the .htaccess file
PPTX
Htaccess crash course for Beginners
PDF
Apache Web Server Administration
PPT
Testing
DOC
12 Rocking Apache .htaccess Tutorial ...
PPT
Tour of sh404SEF - SEO and security for Joomla
testing pdf doc
Comparative Development Methodologies
.htaccess
mod_rewrite bootcamp, Ohio LInux 2011
URL Mapping, with and without mod_rewrite
Part 2 of Advanced SEO tips for Exponent CMS
mod_rewrite
Apache mod_rewrite
mod_rewrite
Google Bot Herding, PageRank Sculpting and Manipulation
mod_rewrite
Learn how to use the .htaccess file
Htaccess crash course for Beginners
Apache Web Server Administration
Testing
12 Rocking Apache .htaccess Tutorial ...
Tour of sh404SEF - SEO and security for Joomla
Ad

Htaccess file tutorial and tips

  • 1. 11/23/13 Htaccess File Tutorial and Tips. www.9lessons.info/2013/11/htaccess-file-tutorial-and-tips.html 1/4 After posting Understanding of Regular Expression article most of my readers are expectingAfter posting Understanding of Regular Expression article most of my readers are expecting .htaccess basics, and I did not find any useful article on Google first page results. Specially I.htaccess basics, and I did not find any useful article on Google first page results. Specially I love to writelove to write.htaccess.htaccess file, using this you can easily configure and redirect Apache Web Serverfile, using this you can easily configure and redirect Apache Web Server file system. This post will explain you how to create friendly URLs, sub domain directory re-file system. This post will explain you how to create friendly URLs, sub domain directory re- directions and many more.directions and many more. Download Script Live Demo Note: .htaccess file will be in hidden format, please change your folder and file settings to view this file. How to Create a .htaccess File? Open any text editor application and file save as with .htaccess name and enablemod_rewrite extension in php.ini file in Apache Web Server configurations. Default directory Listing
  • 2. 11/23/13 Htaccess File Tutorial and Tips. www.9lessons.info/2013/11/htaccess-file-tutorial-and-tips.html 2/4 Disable directory Listing If you want to disable folder files listing, include following code. # Disable Directory Browsing Options All -Indexes Error Pages Here error page is redirecting to error.html. errorDocument 400 http://www.youwebsite.com/error.html errorDocument 401 http://www.youwebsite.com/error.html errorDocument 404 http://www.youwebsite.com/error.html errorDocument 500 http://www.youwebsite.com/error.html RewriteEngine On it is turn on Rewrite Rules in Apache Server. if you want to turn off, just change the value to off. RewriteEngine on
  • 3. 11/23/13 Htaccess File Tutorial and Tips. www.9lessons.info/2013/11/htaccess-file-tutorial-and-tips.html 3/4 Domain Redirection .htacces code for redirecting yourwebsite.com to www.yourwebsite.com RewriteCond %{HTTP_HOST} ^yourwebsite.com RewriteRule (.*) http://www.yourwebsite.com/$1 [R=301,L] Sub Domain Redirection Sub domain redirection mapping to folder. Here http://www.yourwebsite.com is connecting to website_folder folder. RewriteCond %{HTTP_HOST} ^www.yourwebsite.com$ RewriteCond %{REQUEST_URI} !^/website_folder/ RewriteRule (.*) /website_folder/$1 Here http://subdomain.yourwebsite.com is connecting to subdomain_folderfolder. RewriteCond %{HTTP_HOST} ^subdomain.yourwebsite.com$ RewriteCond %{REQUEST_URI} !^/subdomain_folder/ RewriteRule (.*) /subdomain_folder/$1 Htaccess File Inside The Folder. Old Domain Redirection htaccess code for redirecting old domain(abc.com) to new domain(xyz.com). Live demo fglogin.com is now redirecting to oauthlogin.com RewriteCond %{HTTP_HOST} ^abc.com RewriteRule (.*) http://www.xyz.com/$1 [R=301,L] RewriteCond %{HTTP_HOST} ^www.abc.com RewriteRule (.*) http://www.abc.com/$1 [R=301,L] Friendly URLs Friendly/Pretty URLs help in search engine rankings. Profile URL Profile parameter allows [a-zA-Z0-9_-] these inputs. More help read Understanding Regular Expression http://labs.9lessons.info/profile.php?username=srinivas to http://labs.9lessons.info/srinivas RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?username=$1
  • 4. 11/23/13 Htaccess File Tutorial and Tips. www.9lessons.info/2013/11/htaccess-file-tutorial-and-tips.html 4/4 RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?username=$1 Messages URL http://labs.9lessons.info/messages.php?message_username=srinivas to http://labs.9lessons.info/messages/srinivas RewriteRule ^messages/([a-zA-Z0-9_-]+)$ messages.php? message_username=$1 RewriteRule ^messages/([a-zA-Z0-9_-]+)/$ messages.php? message_username=$1 Friends URL http://labs.9lessons.info/friends.php?username=srinivas to http://labs.9lessons.info/friends/srinivas RewriteRule ^friends/([a-zA-Z0-9_-]+)$ friends.php?username=$1 RewriteRule ^friends/([a-zA-Z0-9_-]+)/$ friends.php?username=$1 Friends URL with Two Parameters Here the first parameter allows [a-zA-Z0-9_-] and second parameter allows only number [0-9] http://labs.9lessons.info/friends.php?username=srinivas&page=2 to http://labs.9lessons.info/friends/srinivas/2 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 Hiding File Extension http://www.yourwebsite.com/index.html to http://www.yourwebsite.com/index RewriteRule ^([^/.]+)/?$ $1.html