SlideShare une entreprise Scribd logo
1  sur  24
.htaccess
MemonFaysal
1MemonFaysal
Introduction:
• .htaccess is a configuration file for use on web servers
running the Apache Web Server software. When a .htaccess
file is placed in a directory which is in turn 'loaded via the
Apache Web Server', then the .htaccess file is detected and
executed by the Apache Web Server software. These
.htaccess files can be used to alter the configuration of the
Apache Web Server software to enable/disable additional
functionality and features that the Apache Web Server
software has to offer. These facilities include basic redirect
functionality, for instance if a 404 file not found error occurs,
or for more advanced functions such as content password
protection or image hot link prevention.
• .htaccess isn't difficult to use and is really just made up of a
few simple instructions in a text file.
MemonFaysal 2
Will My Host Support It?
• This is probably the hardest question to give a simple answer to.
Many hosts support .htaccess but don't actually publicise it and
many other hosts have the capability but do not allow their users to
have a .htaccess file. As a general rule, if your server runs Unix or
Linux, or any version of the Apache web server it will support
.htaccess, although your host may not allow you to use it.
A good sign of whether your host allows .htaccess files is if they
support password protection of folders. To do this they will need to
offer .htaccess (although in a few cases they will offer password
protection but not let you use .htaccess). The best thing to do if you
are unsure is to either upload your own .htaccess file and see if it
works or e-mail your web host and ask them.
MemonFaysal 3
What Can I Do?
• You may be wondering what .htaccess can do, or you
may have read about some of its uses but don't realize
how many things you can actually do with it.
There is a huge range of things .htaccess can do
including: password protecting folders, redirecting users
automatically, custom error pages, changing your file
extensions, banning users with certain IP addresses,
only allowing users with certain IP addresses, stopping
directory listings and using a different file as the index
file.
MemonFaysal 4
Creating A .htaccess File
• Creating a .htaccess file may cause you a few problems. Writing the
file is easy, you just need enter the appropriate code into a text
editor (like notepad). You may run into problems with saving the file.
Because .htaccess is a strange file name (the file actually has no
name but a 8 letter file extension) it may not be accepted on certain
systems (e.g. Windows 3.1). With most operating systems, though,
all you need to do is to save the file by entering the name as:
".htaccess"
(including the quotes). If this doesn't work, you will need to name it
something else (e.g. htaccess.txt) and then upload it to the server.
Once you have uploaded the file you can then rename it using an
FTP program.
MemonFaysal 5
Warning
• Before beginning using .htaccess, I should give you one
warning. Although using .htaccess on your server is
extremely unlikely to cause you any problems (if
something is wrong it simply won't work), you should be
wary if you are using the Microsoft FrontPage
Extensions. The FrontPage extensions use the .htaccess
file so you should not really edit it to add your own
information. If you do want to (this is not recommended,
but possible) you should download the .htaccess file
from your server first (if it exists) and then add your code
to the beginning.
MemonFaysal 6
Custom Error Pages
• The first use of the .htaccess file which I will cover is
custom error pages. These will allow you to have your
own, personal error pages (for example when a file is not
found) instead of using your host's error pages or having
no page. This will make your site seem much more
professional in the unlikely event of an error. It will also
allow you to create scripts to notify you if there is an
error (for example I use a PHP script on Free
Webmaster Help to automatically e-mail me when a
page is not found).
MemonFaysal 7
Custom Error Pages (Cont…)
• You can use custom error pages for any error as long as you
know its number (like 404 for page not found) by adding the
following to your .htaccess file:
ErrorDocument errornumber /file.html
For example if I had the file notfound.html in the root directory
of my site and I wanted to use it for a 404 error I would use:
ErrorDocument 404 /notfound.html
If the file is not in the root directory of your site, you just need
to put the path to it:
ErrorDocument 500 /errorpages/500.html
MemonFaysal 8
Common Errors
• These are some of the most common errors:
401 - Authorization Required
400 - Bad request
403 - Forbidden
500 - Internal Server Error
404 - Wrong page
Then, all you need to do is to create a file to display
when the error happens and upload it and the .htaccess
file.
MemonFaysal 9
Stop A Directory Index From Being Shown
• Sometimes, for one reason or another, you will have no
index file in your directory. This will, of course, mean that
if someone types the directory name into their browser, a
full listing of all the files in that directory will be shown.
This could be a security risk for your site.
To prevent against this (without creating lots of new
'index' files, you can enter a command into your
.htaccess file to stop the directory list from being shown:
Options -Indexes
MemonFaysal 10
Deny/Allow Certain IP Addresses
• In some situations, you may want to only allow people
with specific IP addresses to access your site (for
example, only allowing people using a particular ISP to
get into a certain directory) or you may want to ban
certain IP addresses (for example, keeping disruptive
members out of your message boards). Of course, this
will only work if you know the IP addresses you want to
ban and, as most people on the internet now have a
dynamic IP address, so this is not always the best way to
limit usage.
MemonFaysal 11
Block an IP address by using:
deny from 000.000.000.000
where 000.000.000.000 is the IP address. If you only specify 1 or 2 of the
groups of numbers, you will block a whole range.
You can allow an IP address by using:
allow from 000.000.000.000
where 000.000.000.000 is the IP address. If you only specify 1 or 2 of the
groups of numbers, you will allow a whole range.
If you want to deny everyone from accessing a directory, you can use:
deny from all
but this will still allow scripts to use the files in the directory.
MemonFaysal 12
Alternative Index Files
• You may not always want to use index.htm or index.html as
your index file for a directory, for example if you are using
PHP files in your site, you may want index.php to be the index
file for a directory. You are not limited to 'index' files though.
Using .htaccess you can set foofoo.blah to be your index file if
you want to!
Alternate index files are entered in a list. The server will work
from left to right, checking to see if each file exists, if none of
them exist it will display a directory listing (unless, of course,
you have turned this off).
DirectoryIndex index.php index.html index.htm
MemonFaysal 13
Redirection
• One of the most useful functions of the .htaccess file is
to redirect requests to different files, either on the same
server, or on a completely different web site. It can be
extremely useful if you change the name of one of your
files but allow users to still find it. Another use (which I
find very useful) is to redirect to a longer URL, for
example in my newsletters I can use a very short URL
for my affiliate links.
MemonFaysal 14
Redirect a specific file:
Redirect /location/from/root/file.ext
http://www.othersite.com/new/file/location.xyz
• In this above example, a file in the root directory called
oldfile.html would be entered as:
/oldfile.html
and a file in the old subdirectory would be entered as:
/old/oldfile.html
MemonFaysal 15
Redirect whole directories
You can also redirect whole directories of your site using
the .htaccess file, for example if you had a directory called
olddirectory on your site and you had set up the same files
on a new site at: http://www.newsite.com/newdirectory/ you
could redirect all the files in that directory without having to
specify each one:
Redirect /olddirectory
http://www.newsite.com/newdirectory
MemonFaysal 16
Redirect whole directories
Then, any request to your site below /olddirectory will be
redirected to the new site, with the
extra information in the URL added on, for example if someone
typed in:
http://www.youroldsite.com/olddirecotry/oldfiles/images/ima
ge.gif
They would be redirected to:
http://www.newsite.com/newdirectory/oldfiles/images/image
.gif
This can prove to be extremely powerful if used correctly.
MemonFaysal 17
Password Protection
• Although there are many uses of the .htaccess file, by far
the most popular, and probably most useful, is being
able to reliably password protect directories on websites.
Although JavaScript etc. can also be used to do this,
only .htaccess has total security (as someone must know
the password to get into the directory, there are no 'back
doors')
MemonFaysal 18
The .htaccess File
• Adding password protection to a directory using .htaccess takes two
stages. The first part is to add the appropriate lines to your .htaccess
file in the directory you would like to protect. Everything below this
directory will be password protected:
AuthName "Section Name"
AuthType Basic
AuthUserFile /full/path/to/.htpasswd
Require valid-user
• There are a few parts of this which you will need to change for your site.
You should replace "Section Name" with the name of the part of the site
you are protecting e.g. "Members Area".
The /full/parth/to/.htpasswd should be changed to reflect the full server
path to the .htpasswd file (more on this later). If you do not know what
the full path to your web space is, contact your system administrator for
details.
MemonFaysal 19
The .htpasswd File
• Password protecting a directory takes a little more work
than any of the other .htaccess functions because you
must also create a file to contain the usernames and
passwords which are allowed to access the site. These
should be placed in a file which (by default) should be
called .htpasswd. Like the .htaccess file, this is a file with
no name and an 8 letter extension. This can be placed
anywhere within you website (as the passwords are
encrypted) but it is advisable to store it outside the web
root so that it is impossible to access it from the web.
MemonFaysal 20
Entering Usernames & Passwords
• Once you have created your .htpasswd file (you can do this in a
standard text editor) you must enter the usernames and passwords
to access the site. They should be entered as follows:
username:password
• where the password is the encrypted format of the password. To
encrypt the password you will either need to use one of the premade
scripts available on the web or write your own. There is a good
username/password service at the KxS site which will allow you to
enter the user name and password and will output it in the correct
format.
• For multiple users, just add extra lines to your .htpasswd file in the
same format as the first. There are even scripts available for free
which will manage the .htpasswd file and will allow automatic
adding/removing of users etc.
MemonFaysal 21
Accessing The Site
• When you try to access a site which has been protected
by .htaccess your browser will pop up a standard
username/password dialog box. If you don't like this,
there are certain scripts available which allow you to
embed a username/password box in a website to do the
authentication. You can also send the username and
password (unencrypted) in the URL as follows:
http://username:password@www.website.com/directory/
MemonFaysal 22
Summary
• .htaccess is one of the most useful files a webmaster
can use. There are a wide variety of different uses for it
which can save time and increase security on your
website.
MemonFaysal 23
Resource:
• http://www.freewebmasterhelp.com/tutorials/htaccess/
MemonFaysal 24

Contenu connexe

Tendances

Nginx internals
Nginx internalsNginx internals
Nginx internalsliqiang xu
 
Hyperledger Fabric practice (v2.0)
Hyperledger Fabric practice (v2.0) Hyperledger Fabric practice (v2.0)
Hyperledger Fabric practice (v2.0) wonyong hwang
 
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server Push
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server PushReal Time UI with Apache Kafka Streaming Analytics of Fast Data and Server Push
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server PushLucas Jellema
 
Content Delivery Networks (CDN) - What You Really Need to Know
Content Delivery Networks (CDN) - What You Really Need to KnowContent Delivery Networks (CDN) - What You Really Need to Know
Content Delivery Networks (CDN) - What You Really Need to KnowGlobalDots
 
Installation instruction of Testlink
Installation instruction of TestlinkInstallation instruction of Testlink
Installation instruction of Testlinkusha kannappan
 
ما هو ال Dhcp
ما هو ال Dhcpما هو ال Dhcp
ما هو ال Dhcpmohammed-50
 
2 TomcatによるWebアプリケーションサーバ構築 第3章 Apacheの構成
2 TomcatによるWebアプリケーションサーバ構築 第3章 Apacheの構成2 TomcatによるWebアプリケーションサーバ構築 第3章 Apacheの構成
2 TomcatによるWebアプリケーションサーバ構築 第3章 Apacheの構成Enpel
 
2 TomcatによるWebアプリケーションサーバ構築 第4章 Tomcatの構成(3)-データソース
2 TomcatによるWebアプリケーションサーバ構築 第4章 Tomcatの構成(3)-データソース2 TomcatによるWebアプリケーションサーバ構築 第4章 Tomcatの構成(3)-データソース
2 TomcatによるWebアプリケーションサーバ構築 第4章 Tomcatの構成(3)-データソースEnpel
 
2 TomcatによるWebアプリケーションサーバ構築 第4章 Tomcatの構成(1)-仮想ホスト、Apache連携
2 TomcatによるWebアプリケーションサーバ構築 第4章 Tomcatの構成(1)-仮想ホスト、Apache連携2 TomcatによるWebアプリケーションサーバ構築 第4章 Tomcatの構成(1)-仮想ホスト、Apache連携
2 TomcatによるWebアプリケーションサーバ構築 第4章 Tomcatの構成(1)-仮想ホスト、Apache連携Enpel
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node jsAkshay Mathur
 
ReST (Representational State Transfer) Explained
ReST (Representational State Transfer) ExplainedReST (Representational State Transfer) Explained
ReST (Representational State Transfer) ExplainedDhananjay Nene
 
VMware Workstation
VMware WorkstationVMware Workstation
VMware WorkstationBoni Yeamin
 
Kinh nghiệm triển khai K8s tại Stringee - Mr Trần Tiến.pdf
Kinh nghiệm triển khai K8s tại Stringee - Mr Trần Tiến.pdfKinh nghiệm triển khai K8s tại Stringee - Mr Trần Tiến.pdf
Kinh nghiệm triển khai K8s tại Stringee - Mr Trần Tiến.pdfStringee JSC
 
Software Containerization
Software ContainerizationSoftware Containerization
Software ContainerizationRoshan Deniyage
 

Tendances (20)

Nginx internals
Nginx internalsNginx internals
Nginx internals
 
Hyperledger Fabric practice (v2.0)
Hyperledger Fabric practice (v2.0) Hyperledger Fabric practice (v2.0)
Hyperledger Fabric practice (v2.0)
 
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server Push
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server PushReal Time UI with Apache Kafka Streaming Analytics of Fast Data and Server Push
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server Push
 
4. linux file systems
4. linux file systems4. linux file systems
4. linux file systems
 
Content Delivery Networks (CDN) - What You Really Need to Know
Content Delivery Networks (CDN) - What You Really Need to KnowContent Delivery Networks (CDN) - What You Really Need to Know
Content Delivery Networks (CDN) - What You Really Need to Know
 
Json web tokens
Json web tokensJson web tokens
Json web tokens
 
Installation instruction of Testlink
Installation instruction of TestlinkInstallation instruction of Testlink
Installation instruction of Testlink
 
Power-up services with gRPC
Power-up services with gRPCPower-up services with gRPC
Power-up services with gRPC
 
Nginx
NginxNginx
Nginx
 
Apache web server
Apache web serverApache web server
Apache web server
 
ما هو ال Dhcp
ما هو ال Dhcpما هو ال Dhcp
ما هو ال Dhcp
 
2 TomcatによるWebアプリケーションサーバ構築 第3章 Apacheの構成
2 TomcatによるWebアプリケーションサーバ構築 第3章 Apacheの構成2 TomcatによるWebアプリケーションサーバ構築 第3章 Apacheの構成
2 TomcatによるWebアプリケーションサーバ構築 第3章 Apacheの構成
 
2 TomcatによるWebアプリケーションサーバ構築 第4章 Tomcatの構成(3)-データソース
2 TomcatによるWebアプリケーションサーバ構築 第4章 Tomcatの構成(3)-データソース2 TomcatによるWebアプリケーションサーバ構築 第4章 Tomcatの構成(3)-データソース
2 TomcatによるWebアプリケーションサーバ構築 第4章 Tomcatの構成(3)-データソース
 
2 TomcatによるWebアプリケーションサーバ構築 第4章 Tomcatの構成(1)-仮想ホスト、Apache連携
2 TomcatによるWebアプリケーションサーバ構築 第4章 Tomcatの構成(1)-仮想ホスト、Apache連携2 TomcatによるWebアプリケーションサーバ構築 第4章 Tomcatの構成(1)-仮想ホスト、Apache連携
2 TomcatによるWebアプリケーションサーバ構築 第4章 Tomcatの構成(1)-仮想ホスト、Apache連携
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
ReST (Representational State Transfer) Explained
ReST (Representational State Transfer) ExplainedReST (Representational State Transfer) Explained
ReST (Representational State Transfer) Explained
 
VMware Workstation
VMware WorkstationVMware Workstation
VMware Workstation
 
Kinh nghiệm triển khai K8s tại Stringee - Mr Trần Tiến.pdf
Kinh nghiệm triển khai K8s tại Stringee - Mr Trần Tiến.pdfKinh nghiệm triển khai K8s tại Stringee - Mr Trần Tiến.pdf
Kinh nghiệm triển khai K8s tại Stringee - Mr Trần Tiến.pdf
 
Software Containerization
Software ContainerizationSoftware Containerization
Software Containerization
 
Next.js with drupal, the good parts
Next.js with drupal, the good partsNext.js with drupal, the good parts
Next.js with drupal, the good parts
 

En vedette

Apache2 BootCamp : Getting Started With Apache
Apache2 BootCamp : Getting Started With ApacheApache2 BootCamp : Getting Started With Apache
Apache2 BootCamp : Getting Started With ApacheWildan Maulana
 
PHP Training Session 5
PHP Training Session 5PHP Training Session 5
PHP Training Session 5Vishal Kothari
 
Technical SEO: .htaccess & 301 Redirects
Technical SEO:  .htaccess & 301 RedirectsTechnical SEO:  .htaccess & 301 Redirects
Technical SEO: .htaccess & 301 RedirectsRob Bertholf
 
Robots and-sitemap - Version 1.0.1
Robots and-sitemap - Version 1.0.1Robots and-sitemap - Version 1.0.1
Robots and-sitemap - Version 1.0.1Naji El Kotob
 
Introduction to "robots.txt
Introduction to "robots.txtIntroduction to "robots.txt
Introduction to "robots.txtIshan Mishra
 
Learn how to use the .htaccess file
Learn how to use the .htaccess fileLearn how to use the .htaccess file
Learn how to use the .htaccess fileIstogram
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to BootstrapRon Reiter
 
Durability of concrete
Durability of concreteDurability of concrete
Durability of concreteRajesh Prasad
 
Bootstrap 3 - Sleek, intuitive, and powerful mobile first front-end framework...
Bootstrap 3 - Sleek, intuitive, and powerful mobile first front-end framework...Bootstrap 3 - Sleek, intuitive, and powerful mobile first front-end framework...
Bootstrap 3 - Sleek, intuitive, and powerful mobile first front-end framework...Cedric Spillebeen
 

En vedette (13)

Apache2 BootCamp : Getting Started With Apache
Apache2 BootCamp : Getting Started With ApacheApache2 BootCamp : Getting Started With Apache
Apache2 BootCamp : Getting Started With Apache
 
PHP Training Session 5
PHP Training Session 5PHP Training Session 5
PHP Training Session 5
 
Php File Upload
Php File UploadPhp File Upload
Php File Upload
 
Technical SEO: .htaccess & 301 Redirects
Technical SEO:  .htaccess & 301 RedirectsTechnical SEO:  .htaccess & 301 Redirects
Technical SEO: .htaccess & 301 Redirects
 
Robots and-sitemap - Version 1.0.1
Robots and-sitemap - Version 1.0.1Robots and-sitemap - Version 1.0.1
Robots and-sitemap - Version 1.0.1
 
Introduction to "robots.txt
Introduction to "robots.txtIntroduction to "robots.txt
Introduction to "robots.txt
 
Learn how to use the .htaccess file
Learn how to use the .htaccess fileLearn how to use the .htaccess file
Learn how to use the .htaccess file
 
Bootstrap [part 1]
Bootstrap [part 1]Bootstrap [part 1]
Bootstrap [part 1]
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to Bootstrap
 
Durability of concrete
Durability of concreteDurability of concrete
Durability of concrete
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
Bootstrap 3 - Sleek, intuitive, and powerful mobile first front-end framework...
Bootstrap 3 - Sleek, intuitive, and powerful mobile first front-end framework...Bootstrap 3 - Sleek, intuitive, and powerful mobile first front-end framework...
Bootstrap 3 - Sleek, intuitive, and powerful mobile first front-end framework...
 

Similaire à .htaccess

Similaire à .htaccess (20)

sfsa
sfsasfsa
sfsa
 
test pdf
test pdftest pdf
test pdf
 
test
testtest
test
 
testing pdf doc
testing pdf doctesting pdf doc
testing pdf doc
 
Guide 6 - Tapping Into Your Website Configuration File.pdf
Guide 6 - Tapping Into Your Website Configuration File.pdfGuide 6 - Tapping Into Your Website Configuration File.pdf
Guide 6 - Tapping Into Your Website Configuration File.pdf
 
Comparative Development Methodologies
Comparative Development MethodologiesComparative Development Methodologies
Comparative Development Methodologies
 
Htaccess file tutorial and tips
Htaccess file tutorial and tipsHtaccess file tutorial and tips
Htaccess file tutorial and tips
 
7 things every web developer should know about linux administration
7 things every web developer should know about linux administration7 things every web developer should know about linux administration
7 things every web developer should know about linux administration
 
Apache Multiview Vulnerability
Apache Multiview VulnerabilityApache Multiview Vulnerability
Apache Multiview Vulnerability
 
Apache
ApacheApache
Apache
 
Site Mocikut
Site MocikutSite Mocikut
Site Mocikut
 
WordPress Theming 101
WordPress Theming 101WordPress Theming 101
WordPress Theming 101
 
Scalable talk notes
Scalable talk notesScalable talk notes
Scalable talk notes
 
Php 1
Php 1Php 1
Php 1
 
Installing php and my sql locally using xampp
Installing php and my sql locally using xamppInstalling php and my sql locally using xampp
Installing php and my sql locally using xampp
 
Drupal 7x Installation - Introduction to Drupal Concepts
Drupal 7x Installation - Introduction to Drupal ConceptsDrupal 7x Installation - Introduction to Drupal Concepts
Drupal 7x Installation - Introduction to Drupal Concepts
 
Introduction to web page
Introduction to web pageIntroduction to web page
Introduction to web page
 
Apache ppt
Apache pptApache ppt
Apache ppt
 
Apache
ApacheApache
Apache
 
Apache
Apache Apache
Apache
 

Dernier

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 

Dernier (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

.htaccess

  • 2. Introduction: • .htaccess is a configuration file for use on web servers running the Apache Web Server software. When a .htaccess file is placed in a directory which is in turn 'loaded via the Apache Web Server', then the .htaccess file is detected and executed by the Apache Web Server software. These .htaccess files can be used to alter the configuration of the Apache Web Server software to enable/disable additional functionality and features that the Apache Web Server software has to offer. These facilities include basic redirect functionality, for instance if a 404 file not found error occurs, or for more advanced functions such as content password protection or image hot link prevention. • .htaccess isn't difficult to use and is really just made up of a few simple instructions in a text file. MemonFaysal 2
  • 3. Will My Host Support It? • This is probably the hardest question to give a simple answer to. Many hosts support .htaccess but don't actually publicise it and many other hosts have the capability but do not allow their users to have a .htaccess file. As a general rule, if your server runs Unix or Linux, or any version of the Apache web server it will support .htaccess, although your host may not allow you to use it. A good sign of whether your host allows .htaccess files is if they support password protection of folders. To do this they will need to offer .htaccess (although in a few cases they will offer password protection but not let you use .htaccess). The best thing to do if you are unsure is to either upload your own .htaccess file and see if it works or e-mail your web host and ask them. MemonFaysal 3
  • 4. What Can I Do? • You may be wondering what .htaccess can do, or you may have read about some of its uses but don't realize how many things you can actually do with it. There is a huge range of things .htaccess can do including: password protecting folders, redirecting users automatically, custom error pages, changing your file extensions, banning users with certain IP addresses, only allowing users with certain IP addresses, stopping directory listings and using a different file as the index file. MemonFaysal 4
  • 5. Creating A .htaccess File • Creating a .htaccess file may cause you a few problems. Writing the file is easy, you just need enter the appropriate code into a text editor (like notepad). You may run into problems with saving the file. Because .htaccess is a strange file name (the file actually has no name but a 8 letter file extension) it may not be accepted on certain systems (e.g. Windows 3.1). With most operating systems, though, all you need to do is to save the file by entering the name as: ".htaccess" (including the quotes). If this doesn't work, you will need to name it something else (e.g. htaccess.txt) and then upload it to the server. Once you have uploaded the file you can then rename it using an FTP program. MemonFaysal 5
  • 6. Warning • Before beginning using .htaccess, I should give you one warning. Although using .htaccess on your server is extremely unlikely to cause you any problems (if something is wrong it simply won't work), you should be wary if you are using the Microsoft FrontPage Extensions. The FrontPage extensions use the .htaccess file so you should not really edit it to add your own information. If you do want to (this is not recommended, but possible) you should download the .htaccess file from your server first (if it exists) and then add your code to the beginning. MemonFaysal 6
  • 7. Custom Error Pages • The first use of the .htaccess file which I will cover is custom error pages. These will allow you to have your own, personal error pages (for example when a file is not found) instead of using your host's error pages or having no page. This will make your site seem much more professional in the unlikely event of an error. It will also allow you to create scripts to notify you if there is an error (for example I use a PHP script on Free Webmaster Help to automatically e-mail me when a page is not found). MemonFaysal 7
  • 8. Custom Error Pages (Cont…) • You can use custom error pages for any error as long as you know its number (like 404 for page not found) by adding the following to your .htaccess file: ErrorDocument errornumber /file.html For example if I had the file notfound.html in the root directory of my site and I wanted to use it for a 404 error I would use: ErrorDocument 404 /notfound.html If the file is not in the root directory of your site, you just need to put the path to it: ErrorDocument 500 /errorpages/500.html MemonFaysal 8
  • 9. Common Errors • These are some of the most common errors: 401 - Authorization Required 400 - Bad request 403 - Forbidden 500 - Internal Server Error 404 - Wrong page Then, all you need to do is to create a file to display when the error happens and upload it and the .htaccess file. MemonFaysal 9
  • 10. Stop A Directory Index From Being Shown • Sometimes, for one reason or another, you will have no index file in your directory. This will, of course, mean that if someone types the directory name into their browser, a full listing of all the files in that directory will be shown. This could be a security risk for your site. To prevent against this (without creating lots of new 'index' files, you can enter a command into your .htaccess file to stop the directory list from being shown: Options -Indexes MemonFaysal 10
  • 11. Deny/Allow Certain IP Addresses • In some situations, you may want to only allow people with specific IP addresses to access your site (for example, only allowing people using a particular ISP to get into a certain directory) or you may want to ban certain IP addresses (for example, keeping disruptive members out of your message boards). Of course, this will only work if you know the IP addresses you want to ban and, as most people on the internet now have a dynamic IP address, so this is not always the best way to limit usage. MemonFaysal 11
  • 12. Block an IP address by using: deny from 000.000.000.000 where 000.000.000.000 is the IP address. If you only specify 1 or 2 of the groups of numbers, you will block a whole range. You can allow an IP address by using: allow from 000.000.000.000 where 000.000.000.000 is the IP address. If you only specify 1 or 2 of the groups of numbers, you will allow a whole range. If you want to deny everyone from accessing a directory, you can use: deny from all but this will still allow scripts to use the files in the directory. MemonFaysal 12
  • 13. Alternative Index Files • You may not always want to use index.htm or index.html as your index file for a directory, for example if you are using PHP files in your site, you may want index.php to be the index file for a directory. You are not limited to 'index' files though. Using .htaccess you can set foofoo.blah to be your index file if you want to! Alternate index files are entered in a list. The server will work from left to right, checking to see if each file exists, if none of them exist it will display a directory listing (unless, of course, you have turned this off). DirectoryIndex index.php index.html index.htm MemonFaysal 13
  • 14. Redirection • One of the most useful functions of the .htaccess file is to redirect requests to different files, either on the same server, or on a completely different web site. It can be extremely useful if you change the name of one of your files but allow users to still find it. Another use (which I find very useful) is to redirect to a longer URL, for example in my newsletters I can use a very short URL for my affiliate links. MemonFaysal 14
  • 15. Redirect a specific file: Redirect /location/from/root/file.ext http://www.othersite.com/new/file/location.xyz • In this above example, a file in the root directory called oldfile.html would be entered as: /oldfile.html and a file in the old subdirectory would be entered as: /old/oldfile.html MemonFaysal 15
  • 16. Redirect whole directories You can also redirect whole directories of your site using the .htaccess file, for example if you had a directory called olddirectory on your site and you had set up the same files on a new site at: http://www.newsite.com/newdirectory/ you could redirect all the files in that directory without having to specify each one: Redirect /olddirectory http://www.newsite.com/newdirectory MemonFaysal 16
  • 17. Redirect whole directories Then, any request to your site below /olddirectory will be redirected to the new site, with the extra information in the URL added on, for example if someone typed in: http://www.youroldsite.com/olddirecotry/oldfiles/images/ima ge.gif They would be redirected to: http://www.newsite.com/newdirectory/oldfiles/images/image .gif This can prove to be extremely powerful if used correctly. MemonFaysal 17
  • 18. Password Protection • Although there are many uses of the .htaccess file, by far the most popular, and probably most useful, is being able to reliably password protect directories on websites. Although JavaScript etc. can also be used to do this, only .htaccess has total security (as someone must know the password to get into the directory, there are no 'back doors') MemonFaysal 18
  • 19. The .htaccess File • Adding password protection to a directory using .htaccess takes two stages. The first part is to add the appropriate lines to your .htaccess file in the directory you would like to protect. Everything below this directory will be password protected: AuthName "Section Name" AuthType Basic AuthUserFile /full/path/to/.htpasswd Require valid-user • There are a few parts of this which you will need to change for your site. You should replace "Section Name" with the name of the part of the site you are protecting e.g. "Members Area". The /full/parth/to/.htpasswd should be changed to reflect the full server path to the .htpasswd file (more on this later). If you do not know what the full path to your web space is, contact your system administrator for details. MemonFaysal 19
  • 20. The .htpasswd File • Password protecting a directory takes a little more work than any of the other .htaccess functions because you must also create a file to contain the usernames and passwords which are allowed to access the site. These should be placed in a file which (by default) should be called .htpasswd. Like the .htaccess file, this is a file with no name and an 8 letter extension. This can be placed anywhere within you website (as the passwords are encrypted) but it is advisable to store it outside the web root so that it is impossible to access it from the web. MemonFaysal 20
  • 21. Entering Usernames & Passwords • Once you have created your .htpasswd file (you can do this in a standard text editor) you must enter the usernames and passwords to access the site. They should be entered as follows: username:password • where the password is the encrypted format of the password. To encrypt the password you will either need to use one of the premade scripts available on the web or write your own. There is a good username/password service at the KxS site which will allow you to enter the user name and password and will output it in the correct format. • For multiple users, just add extra lines to your .htpasswd file in the same format as the first. There are even scripts available for free which will manage the .htpasswd file and will allow automatic adding/removing of users etc. MemonFaysal 21
  • 22. Accessing The Site • When you try to access a site which has been protected by .htaccess your browser will pop up a standard username/password dialog box. If you don't like this, there are certain scripts available which allow you to embed a username/password box in a website to do the authentication. You can also send the username and password (unencrypted) in the URL as follows: http://username:password@www.website.com/directory/ MemonFaysal 22
  • 23. Summary • .htaccess is one of the most useful files a webmaster can use. There are a wide variety of different uses for it which can save time and increase security on your website. MemonFaysal 23