12/23/2008

Great htaccess tip for web masters!

These are one of the best tips and tricks involving .htaccess capabilities listed in 16 Useful .htaccess Tricks and Hacks For Web Developers! Check it out.

Quote:

1. Creating a custom error page with .htaccess on a linux apache is a very simple task. Using you a text editor like notepad you create an .htaccess files. Custom error pages give your website an professional look and catch those visitors who reach your website following a back link.

ErrorDocument 401 /error/401.php
ErrorDocument 403 /error/403.php
ErrorDocument 404 /error/404.php
ErrorDocument 500 /error/500.php

2. How to set the timezone on your server

SetEnv TZ America/Houston

3. Block IPs Using htaccess
Sometime you need to block certain IPs from accessing your entire site or directory. Its pretty simple task. All you have to do is inside the .htaccess file is put the following code.

allow from all
deny from 145.186.14.122
deny from 124.15

If you use the whole IP or a part of the IP to block and add the new ones in a new line.
When someone trying to access your site from the banned ip they will get a 403 error access forbidden message.

4. SEO Friendly 301 permanent redirects for bad/old links and moved links

Redirect 301 /d/file.html http://www.htaccesselite.com/r/file.html

5. Set the Email Address for the Server Administrator - Using this code you can specifying the default email address for the server administrator.

ServerSignature EMail
SetEnv SERVER_ADMIN default@domain.com

6. Hotlinking protection with .htaccess is very important because anyone can hot link to your images and eat up all your bandwith of your server. The following code will help you to prevent that.

Options +FollowSymlinks
# Protect Hotlinking
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domainname\.com/ [nc]
RewriteRule .*\.(gif|jpg|png)$ http://domainname.com/img/hotlink_f_o.png [nc]

7. Block all requests from user agent - by creating a perfect .htaccess ban list, you can block all of unwanted user agents that will keep your server load down. Also Check out this interesting thread on webmaster world about the 228 user agents ban list.

## .htaccess Code :: BEGIN
## Block Bad Bots by user-Agent
SetEnvIfNoCase user-Agent ^FrontPage [NC,OR]
SetEnvIfNoCase user-Agent ^Java.* [NC,OR]
SetEnvIfNoCase user-Agent ^Microsoft.URL [NC,OR]
SetEnvIfNoCase user-Agent ^MSFrontPage [NC,OR]
SetEnvIfNoCase user-Agent ^Offline.Explorer [NC,OR]
SetEnvIfNoCase user-Agent ^[Ww]eb[Bb]andit [NC,OR]
SetEnvIfNoCase user-Agent ^Zeus [NC]

Order Allow,Deny
Allow from all
Deny from env=bad_bot

## .htaccess Code :: END

8. Redirect everyone to different site except few IP
-If you want to redirect all the visitors to a different IP. Also give access to certain few IPs. You can use the code below

ErrorDocument 403 http://www.youdomain.com
Order deny,allow
Deny from all
Allow from 124.34.48.165
Allow from 102.54.68.123

9. Don’t want to display download request - Usually when you try to download something from a web server you get a request asking whether you want to save the file or open it.
To avoid that you can use the below code on your .htaccess file.

AddType application/octet-stream .pdf
AddType application/octet-stream .zip
AddType application/octet-stream .mov

10. Change the file type - Make any file be a certain kind of file type Makes image.jpg, index.html, default.cgi all act as php


ForceType application/x-httpd-php
SetHandler application/x-httpd-php

11. Block access to your .htaccess file - By adding he following code to your htaccess file will prevent attempts to access your htaccess file. This extra layer of security protects your htaccess file by displaying a 403 error message on the browser.

# secure htaccess file

 order allow,deny
 deny from all


12. Protect access to certain specific file on your server - this can be done by adding the below mentioned code. For example you want to block with the file name default.jpg This will prevent the viewing of this file.

# prevent access of a certain file

 order allow,deny
 deny from all


13. Prevent access to unauthorized browsing - Protecting specific directory browsing can be done by intructing the server to serve a Forbidden and Authorization required message while anyone requests to view that particular directory. Usually if you site doesn’t have a default index page any files within that directory is accessible to the visitors. To avoid that use the following code in the .htaccess file.

# disable directory browsing
Options All -Indexes

14. Setting the default page
- You can set the default page of a directory to any page you like. For example in this code the default page is set as about.html instead of index.html

# serve alternate default index page
DirectoryIndex about.html

15. Password protect your directories and files
- You can create authentication for certain files and directories from being access. The code has examples of both password protection for a single file and password protection for a entire directory.

# to protect a file

AuthType Basic
AuthName “Prompt”
AuthUserFile /home/path/.htpasswd
Require valid-user

# password-protect a directory
resides
AuthType basic
AuthName “This directory is protected”
AuthUserFile /home/path/.htpasswd
AuthGroupFile /dev/null
Require valid-user

16. Redirect an old domain to a new domain
- Using htaccess file you can redirect a old domain name to a new domain by adding the following code into the htaccess file. Basically what it does is it will remap the old domain to the new one.

# redirect from old domain to new domain
RewriteEngine On
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]

73 comments:

逆円助 said...

さあ、今夏も新たな出会いを経験してみませんか?当サイトは円助交際の逆、つまり女性が男性を円助する『逆円助交際』を提供します。逆円交際を未経験の方でも気軽に遊べる大人のマッチングシステムです。年齢上限・容姿・経験一切問いません。男性の方は無料で登録して頂けます。貴方も新たな出会いを経験してみませんか

精神年齢 said...

みんなの精神年齢を測定できる、メンタル年齢チェッカーで秘められた年齢がズバリわかっちゃう!かわいいあの子も実は精神年齢オバサンということも…合コンや話のネタに一度チャレンジしてみよう

メル友募集 said...

最近仕事ばかりで毎日退屈してます。そろそろ恋人欲しいです☆もう夏だし海とか行きたいな♪ k.c.0720@docomo.ne.jp 連絡待ってるよ☆

家出 said...

最近TVや雑誌で紹介されている家出掲示板では、全国各地のネットカフェ等を泊り歩いている家出娘のメッセージが多数書き込みされています。彼女たちはお金がないので掲示板で知り合った男性の家にでもすぐに泊まりに行くようです。あなたも書き込みに返事を返してみませんか

動物占い said...

あなたの性格を、動物に例えて占っちゃいます。もしかしたらこんな動物かも!?動物占いをうまく使って、楽しい人間関係を築いてください

家出 said...

家出中の女性や泊まる所が無い女性達がネットカフェなどで、飲み放題のドリンクで空腹を満たす生活を送っています。当サイトはそんな女性達をサポートしたいという人たちと困っている女性たちの為のサイトです

セレブラブ said...

セレブ女性との割り切りお付き合いで大金を稼いでみませんか?女性に癒しと快楽、男性に謝礼とお互い満たしあえる当サイト、セレブラブはあなたの登録をお待ちしております。

夏フェス!! said...

夏フェス一緒に行ってくれる人募集!!夏の思い出一緒につくろぉ☆ megumi-0830@docomo.ne.jp 連絡してね♪

無料ゲーム said...

あなたのゲーマー度を無料ゲーム感覚で測定します。15個の質問に答えるだけの簡単測定で一度遊んでみませんか?ゲームが得意な人もそうでない人もぜひどうぞ。

素人 said...

Hな女性たちは素人ホストを自宅やホテルに呼び、ひとときの癒しを求めていらっしゃいます。当サイトでは男性ホスト様の人員が不足しており、一日3~4人の女性の相手をするホストもおられます。興味を持たれた方は当サイトにぜひお越しください

出会い系 said...

実は出会い系には…関係者用入り口があるのを知っていますか?広告主やスポンサー用に用意されたIDではサクラや業者が立ち入ることが出来ないようになっているのです。当サイトでは極秘に入手した関係者用URLが公開されています

逆援助 said...

男性はお金、女性は快楽を得る逆援助に興味はありませんか?お金を払っても性的欲求を満たしたいセレブ達との割り切り1日のお付き合いで当サイトでは大金を得ることができます。無料登録なのでアルバイト感覚でOK、詳しくはTOPページでどうぞ。

友達募集 said...

ホムペ完成記念!私の事みんなに知ってもらいたくて頑張りましたぁ。色々とご感想をお待ちしているので思った事を意見してください。メアドはほむぺにのせてありますぅ!★ fan.jna@docomo.ne.jp

家出 said...

夏休みで気軽に家出する女子○生が急増しています。しかし家出したはいいものの泊る所やお金が無い彼女たちは、掲示板などで泊めてくれる男性を探す子も多いようです。当掲示板にも夏休みに入ってから通常の3倍以上のメッセージが寄せられています

人妻 said...

今最もアツイバイトは人妻とのセフレ契約です。当サイトではお金を払ってでもセフレがほしい人妻が集まり、男性会員様との逆援生活を待っています。当サイトで欲求不満の女性との出会いをしてみませんか

素人 said...

素人ホストでは、男性のテクニック次第で女性会員様から高額な謝礼がもらえます。欲求不満な人妻や、男性と出会いが無い女性達が当サイトで男性を求めていらっしゃいます。興味のある方はTOPページからどうぞ

友達募集中 said...

少し魅惑な自分をネットだから公開してみました。普段言えない事など、思い切って告白しているプロフなので興味ある方はぜひ除いてみてください連絡待ってまぁす。 hinyaaaaa@docomo.ne.jp

Anonymous said...

order xanax no prescription different kinds xanax bars - how many xanax pills are lethal

Anonymous said...

valium 5mg buy valium australia - what is valium good for

Anonymous said...

generic zolpidem zolpidem alcohol interaction - zolpidem tartrate common side effects

Anonymous said...

xanax online xanax for anxiety insomnia - generic xanax 2mg pills

Anonymous said...

buy lorazepam ativan vs xanax for anxiety - buy lorazepam china

Anonymous said...

buy ambien ambien side effects vertigo - is buying ambien online illegal

Anonymous said...

xanax without prescription order cheap xanax online - buy xanax online united states

Anonymous said...

diazepam online cheapest diazepam online no prescription - diazepam 5mg vs xanax

Anonymous said...

diazepam overdose what drug category is diazepam - diazepam dosage for dogs with seizures

Anonymous said...

generic xanax xanax withdrawal symptoms timeline - best place order xanax online

Anonymous said...

buy diazepam diazepam 5mg - diazepam dosage elderly

Anonymous said...

discount ativan side effects of ativan in women - ativan withdrawal muscle twitches

Anonymous said...

buy valium overseas valium drug life - valium and xanax

Anonymous said...

buy somas can u overdose carisoprodol - buy soma online cheap no prescription

Anonymous said...

valium no prescription overnight makes best generic valium - buy valium online cheap uk

Anonymous said...

buy valium online valium 10mg duration - valium for anxiety attacks

Anonymous said...

carisoprodol 350 mg soma medication alcohol - somanabolic muscle maximizer review yahoo

Anonymous said...

valium without prescription 5mg valium and alcohol - buy valium hong kong

Anonymous said...

generic valium online valium hard drug - buy valium online with mastercard

Anonymous said...

Hello! I could have sworn I've been to this website before but after browsing through a few of the articles I realized it's new to me.

Anyways, I'm certainly happy I came across it and I'll be book-marking it and checking back often!
Here is my blog clean my pc

Anonymous said...

Usually I don't learn post on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been amazed me. Thanks, quite great post.
Review my web-site :: golden virginia tobacco

Anonymous said...

I like what you guys are up too. This type of clever work and coverage!
Keep up the fantastic works guys I've included you guys to blogroll.
Look at my webpage ... captain black

Anonymous said...

Today, while I was at work, my sister stole
my iphone and tested to see if it can survive a
30 foot drop, just so she can be a youtube sensation. My iPad is now destroyed
and she has 83 views. I know this is completely off topic but
I had to share it with someone!
Stop by my blog post van nelle zware

Anonymous said...

Hello there! I simply would like to give you a huge thumbs up
for the excellent information you have here on this post.
I am returning to your blog for more soon.
my page > golden virginia

Anonymous said...

Hello, all the time i used to check blog posts here early in the break of day, because i
love to find out more and more.
Here is my web site ... borkum riff

Anonymous said...

This is my first time pay a quick visit at here
and i am genuinely happy to read all at single place.
Take a look at my web-site ... old holborn

Anonymous said...

Croriespeetle order ativan online - ativan cost http://www.lorazepamonlinesales.com/

Anonymous said...

Bowel Relaxing Medications prednisone sale - prednisone without prescription http://www.prednisone4sale.com/#prednisone-without-prescription

Anonymous said...

advitleva cheapest premarin - discount premarin http://www.premarindiscount.com/

Anonymous said...

Drugs David Aponte order topamax - buy topamax without prescription http://www.topamaxforless.com/

Anonymous said...

dalsCleax buy accutane without prescription - generic isotretinoin http://www.isotretinoinlowcost.com/#generic-isotretinoin

Anonymous said...

Teas Traditional Chinese Medicine price of diflucan - diflucan fluconazole 150mg http://www.diflucansaleonline.net/#diflucan-fluconazole-150mg , [url=http://www.diflucansaleonline.net/#cheap-diflucan-online ]cheap diflucan online [/url]

Anonymous said...

Zyladex Plus Diet Pills generic lexapro online - lexapro cost http://www.costoflexaproonline.net/#lexapro-cost , [url=http://www.costoflexaproonline.net/#lexapro-for-sale ]lexapro for sale [/url]

Anonymous said...

Drug Compatibility Charts sibutramine online no prescription - meridia pills for sale http://www.meridiaonlineorder.net/#meridia-pills-for-sale , [url=http://www.meridiaonlineorder.net/#order-sibutramine-online ]order sibutramine online [/url]

Anonymous said...

1, purchase imitrex - generic imitrex price http://www.brawr.net/#generic-imitrex-price , [url=http://www.brawr.net/#imitrex-pills ]imitrex pills [/url]

Anonymous said...

tfv zoloft no prescription - buy zoloft online http://www.zoloftonlinesales.net/#cheap-sertraline, [url=http://www.zoloftonlinesales.net/#cheap-sertraline]buy sertraline online no prescription [/url]

Anonymous said...

sob purchase neurontin - neurontin pills http://www.neurontinonlinesales.net/#neurontin-pills , [url=http://www.neurontinonlinesales.net/#gabapentin-sale ]gabapentin sale [/url]

Anonymous said...

Thаnκs for finally talking аbоut > "Great htaccess tip for web masters!" < Loved it!

Feel free to surf to my web blog :: pаyday loans

Anonymous said...

2013 prednisone medication - prednisone no prescription http://www.prednisoneonlinerx.net/index.html, prednisone online

Anonymous said...

This website was... hoω do I ѕаy it?
Releνаnt!! Finally I've found something that helped me. Cheers!

Also visit my homepage ... payday loans
My page > payday loans

Anonymous said...

Its like you read mу mind! You аppear to knoω a lot about thіs, like уou wrotе the bоok in іt or
somethіng. I think that you could do with somе ρіcѕ tο dгіve the
mesѕаge home a lіttle bit, but insteaԁ
οf thаt, thiѕ is magnificent blоg.
A great read. I will dеfinitely be bаck.


Ηere is my blog post; quick loans

Anonymous said...

http://technologiesuae.com/#sale xanax generic pictures pills - yellow xanax bars 039

Anonymous said...

ya ce ra zcfs sank blsv xgdfox kmynat bhlzayhs zu lx [url=http://www.louboutinfrpascher.fr]louboutin chaussures[/url] rlmx [url=http://www.louboutinfrpascher.fr]chaussure christian louboutin pas cher[/url] pdhn afye fkbjpr bwtbfh mwotmedm us un wxyg lemj dhjj [url=http://www.louboutinfrpascher.fr]chaussures louboutin pas cher[/url] olhwgy wzjnos yquoaavz jf sn nxfs oehc ujtf lbesua jgapfl [url=http://www.louboutinfrpascher.fr]christian louboutin escarpin[/url] xyvrccnm mv iy vewv vnpn gouj [url=http://www.louboutinfrpascher.fr]http://www.louboutinfrpascher.fr[/url] xgrwus zulpxn muxaafsa lx mz afha [url=http://www.louboutinfrpascher.fr]botte christian louboutin[/url] meln qsov iqayyc zpyjte prvugsxr po pe bvkc hgay wjyg xfxe

Anonymous said...

Thanks to my father who told me about this weblog, this webpage is in fact remarkable.


my web page :: green coffee extract weight loss

Anonymous said...

It's really nice that you've taken the hard work
to help those out there who are seeking out resources on this subject.

Your serious commitment to getting the answer out there appears to
be amazingly beneficial and has permitted students much like me to arrive at their objectives.
Do know that this work means a lot to all of us.



My blog post ... meule de foin

Anonymous said...

Hello Dear, are you in fact visiting this web site on a regular basis, if so
afterward you will absolutely take nice experience.

my site; Discount Codes

Anonymous said...

I all the tіmе emailed this web ѕіte poѕt pagе
to all my аssociates, becаuse if lіke tо
rеad it next mу links ωill toο.

Feel free tо surf tο my blog pοst - payday loans uk

Anonymous said...

Hi there would you mind sharing which blog platform you're using? I'm looking to start my own blog in the
near future but I'm having a hard time choosing between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then most blogs and I'm looking for something completely
unique. P.S My apologies for getting off-topic but
I had to ask!

my web site BlackPeopleMeet browse

Anonymous said...

Remarkable! ӏts actuallу aωeѕomе
рost, I have got much clеar idea abοut
frοm thіs aгticle.

Herе is my wеbѕite; reputation management

Anonymous said...

I really like what you guys are up too. This type
of clever work and reporting! Keep up the awesome works guys I've incorporated you guys to
my blogroll.

Here is my blog; check my credit free

Anonymous said...

I like what you guys
are usually up too. This kind of clever work and exposure!



Keep up the superb works guys I've added you guys to blogroll.

My blog post :: stall mats for gym floor

Anonymous said...

I need to to thank you for this very good read!!
I certainly enjoyed every bit of it. I have got you book-marked to check out new stuff you post

Also visit my web site :: datacenter virtualization

Anonymous said...

Everyone loves what you guys
are usually up too. Such clever work and reporting!


Keep up the terrific works guys I've included you guys to our blogroll.

Also visit my blog :: fitness equipment stores

Anonymous said...

Hi, I do believe this is an excellent blog. I stumbledupon it ;) I may return once again since I saved as a
favorite it. Money and freedom is the best way to change, may you be rich and continue to guide
other people.

Here is my blog post - cheap houses

Anonymous said...

I visited many websites but the audio quality for audio songs
existing at this website is really fabulous.

Here is my web-site: dallas defense

Anonymous said...

Howdy! Someone in my Facebook group shared this site with us so I came to check it
out. I'm definitely enjoying the information.
I'm bookmarking and will be tweeting this to my
followers! Outstanding blog and terrific design.


Also visit my weblog ... naruto videos :: ::