<!DOCTYPE html>
    <html lang="vi" xmlns="http://www.w3.org/1999/xhtml" prefix="og: http://ogp.me/ns#">
    <head>
<title>Một số công dụng của htaccess</title>
<meta name="description" content="Một số công dụng của htaccess - Savefile - Blog - https&#x3A;&#x002F;&#x002F;tocdoviet.com&#x002F;blog&#x002F;savefile&#x002F;Tai-lieu-SEO&#x002F;Mot-so-cong-dung-cua-htaccess-130.html">
<meta name="author" content="Tốc Độ Việt - Dịch vụ Hosting, Tên miền, Máy chủ, Thiết kế Website">
<meta name="copyright" content="Tốc Độ Việt - Dịch vụ Hosting, Tên miền, Máy chủ, Thiết kế Website [loc.thb@bazan.vn]">
<meta name="generator" content="NukeViet v4.5">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta property="og:title" content="Một số công dụng của htaccess">
<meta property="og:type" content="website">
<meta property="og:description" content="Savefile - Blog - https&#x3A;&#x002F;&#x002F;tocdoviet.com&#x002F;blog&#x002F;savefile&#x002F;Tai-lieu-SEO&#x002F;Mot-so-cong-dung-cua-htaccess-130.html">
<meta property="og:site_name" content="Tốc Độ Việt - Dịch vụ Hosting, Tên miền, Máy chủ, Thiết kế Website">
<meta property="og:url" content="https://tocdoviet.com/blog/savefile/Tai-lieu-SEO/Mot-so-cong-dung-cua-htaccess-130.html">
<link rel="shortcut icon" href="https://tocdoviet.com/favicon.ico">
<link rel="canonical" href="https://tocdoviet.com/blog/savefile/Tai-lieu-SEO/Mot-so-cong-dung-cua-htaccess-130.html">
<link rel="alternate" href="https://tocdoviet.com/blog/rss/" title="Blog" type="application/rss+xml">
<link rel="alternate" href="https://tocdoviet.com/blog/rss/Cau-hoi-thuong-gap/" title="Blog - Câu hỏi thường gặp" type="application/rss+xml">
<link rel="alternate" href="https://tocdoviet.com/blog/rss/Tai-lieu-Ten-Mien/" title="Blog - Tài liệu Tên Miền" type="application/rss+xml">
<link rel="alternate" href="https://tocdoviet.com/blog/rss/Tai-lieu-Hosting/" title="Blog - Tài liệu Hosting" type="application/rss+xml">
<link rel="alternate" href="https://tocdoviet.com/blog/rss/Tai-lieu-May-Chu/" title="Blog - Tài liệu Máy Chủ" type="application/rss+xml">
<link rel="alternate" href="https://tocdoviet.com/blog/rss/Tai-lieu-Ma-Nguon/" title="Blog - Tài liệu Mã Nguồn" type="application/rss+xml">
<link rel="alternate" href="https://tocdoviet.com/blog/rss/Tai-lieu-SEO/" title="Blog - Tài liệu SEO" type="application/rss+xml">
<link rel="alternate" href="https://tocdoviet.com/blog/rss/Tai-lieu-Website/" title="Blog - Tài liệu Website" type="application/rss+xml">
<link rel="alternate" href="https://tocdoviet.com/blog/rss/Tai-lieu-Phan-Mem/" title="Blog - Tài liệu Phần Mềm" type="application/rss+xml">
<link rel="alternate" href="https://tocdoviet.com/blog/rss/Tai-lieu-May-Tinh/" title="Blog - Tài liệu Máy Tính" type="application/rss+xml">
<link rel="preload" as="style" href="https://tocdoviet.com/assets/css/font-awesome.min.css" type="text/css">
<link rel="preload" as="style" href="https://tocdoviet.com/themes/default/css/bootstrap.min.css" type="text/css">
<link rel="preload" as="style" href="https://tocdoviet.com/themes/default/css/style.css" type="text/css">
<link rel="preload" as="style" href="https://tocdoviet.com/themes/default/css/style.responsive.css" type="text/css">
<link rel="preload" as="style" href="https://tocdoviet.com/themes/default/css/news.css" type="text/css">
<link rel="preload" as="style" href="https://tocdoviet.com/themes/default/css/custom.css" type="text/css">
<link rel="preload" as="script" href="https://tocdoviet.com/assets/js/jquery/jquery.min.js" type="text/javascript">
<link rel="preload" as="script" href="https://tocdoviet.com/assets/js/language/vi.js" type="text/javascript">
<link rel="preload" as="script" href="https://tocdoviet.com/assets/js/DOMPurify/purify3.js" type="text/javascript">
<link rel="preload" as="script" href="https://tocdoviet.com/assets/js/global.js" type="text/javascript">
<link rel="preload" as="script" href="https://tocdoviet.com/assets/js/site.js" type="text/javascript">
<link rel="preload" as="script" href="https://tocdoviet.com/themes/default/js/news.js" type="text/javascript">
<link rel="preload" as="script" href="https://tocdoviet.com/themes/default/js/main.js" type="text/javascript">
<link rel="preload" as="script" href="https://tocdoviet.com/themes/default/js/custom.js" type="text/javascript">
<link rel="preload" as="script" href="https://tocdoviet.com/themes/default/js/bootstrap.min.js" type="text/javascript">
<link rel="stylesheet" href="https://tocdoviet.com/assets/css/font-awesome.min.css">
<link rel="stylesheet" href="https://tocdoviet.com/themes/default/css/bootstrap.min.css">
<link rel="stylesheet" href="https://tocdoviet.com/themes/default/css/style.css">
<link rel="stylesheet" href="https://tocdoviet.com/themes/default/css/style.responsive.css">
<link rel="StyleSheet" href="https://tocdoviet.com/themes/default/css/news.css">
<link rel="stylesheet" href="https://tocdoviet.com/themes/default/css/custom.css">
<style>
#gom-all-in-one{margin-bottom: 150px;}
@-webkit-keyframes phone-vr-circle-fill {
0% {-webkit-transform: rotate(0) scale(1) skew(1deg); }
10% {-webkit-transform: rotate(-25deg) scale(1) skew(1deg);}
20% {-webkit-transform: rotate(25deg) scale(1) skew(1deg);}
30% {-webkit-transform: rotate(-25deg) scale(1) skew(1deg);}
40% {-webkit-transform: rotate(25deg) scale(1) skew(1deg);}
50% {-webkit-transform: rotate(0) scale(1) skew(1deg);}
100% {-webkit-transform: rotate(0) scale(1) skew(1deg);}
}
@-webkit-keyframes zoom{0%{transform:scale(.9)}70%{transform:scale(1);box-shadow:0 0 0 15px transparent}100%{transform:scale(.9);box-shadow:0 0 0 0 transparent}}@keyframes zoom{0%{transform:scale(.9)}70%{transform:scale(1);box-shadow:0 0 0 15px transparent}100%{transform:scale(.9);box-shadow:0 0 0 0 transparent}}
#button-contact-vr{right:0}
.phone-bar a{
left:auto;right:30px;padding:8px 55px 7px 15px
}
#button-contact-vr.active #gom-all-in-one .button-contact
{
margin-left:100%
}
#button-contact-vr{bottom:30%}
#gom-all-in-one #zalo-vr {
transition: 1s all;
-moz-transition: 1s all;
-webkit-transition: 1s all;
}
#zalo-vr .phone-vr-circle-fill {
box-shadow: 0 0 0 0 #2196f3;
background-color: rgba(33,150,243,.7);
}
.phone-vr-circle-fill {
width: 65px;
height: 65px;
top: 12px;
left: 12px;
position: absolute;
box-shadow: 0 0 0 0 #c31d1d;
background-color: rgba(230,8,8,.7);
border-radius: 50%;
border: 2px solid transparent;
-webkit-animation: phone-vr-circle-fill 2.3s infinite ease-in-out;
animation: phone-vr-circle-fill 2.3s infinite ease-in-out;
transition: all .5s;
-webkit-transform-origin: 50% 50%;
-ms-transform-origin: 50% 50%;
transform-origin: 50% 50%;
-webkit-animuiion: zoom 1.3s infinite;
animation: zoom 1.3s infinite;
}
.phone-vr-img-circle a {
display: block;
line-height: 37px;
}
.phone-vr-img-circle img {
max-height: 25px;
max-width: 27px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
-moz-transform: translate(-50%,-50%);
-webkit-transform: translate(-50%,-50%);
-o-transform: translate(-50%,-50%);
}
#zalo-vr .phone-vr-img-circle {
background-color: #2196f3;
}
.phone-vr-img-circle {
background-color: #e60808;
width: 40px;
height: 40px;
line-height: 40px;
top: 25px;
left: 25px;
position: absolute;
border-radius: 50%;
overflow: hidden;
display: flex;
justify-content: center;
-webkit-animation: phonering-alo-circle-img-anim 1s infinite ease-in-out;
animation: phone-vr-circle-fill 1s infinite ease-in-out;
}
#button-contact-vr .button-contact .phone-vr {
position: relative;
visibility: visible;
background-color: transparent;
width: 90px;
height: 90px;
cursor: pointer;
z-index: 11;
-webkit-backface-visibility: hidden;
-webkit-transform: translateZ(0);
transition: visibility .5s;
left: 0;
bottom: 0;
display: block;
}
#gom-all-in-one #phone-vr {
transition: .7s all;
-moz-transition: .7s all;
-webkit-transition: .7s all;
}
#button-contact-vr .button-contact {
position: relative;
margin-top: 5px;
}
#phone-vr .phone-vr-circle-fill {
opacity: .7;
box-shadow: 0 0 0 0 #d33;
}
.phone-bar a, #phone-vr .phone-vr-circle-fill, #phone-vr .phone-vr-img-circle, #phone-vr .phone-bar a {
background-color: #d33;
}
#button-contact-vr {
bottom: 30%;
}
#button-contact-vr {
position: fixed;
bottom: 0;
z-index: 99999;
}
#popup-showroom-vr, div#popup-form-contact-vr {
display: none;
}
.bg-popup-vr {
position: absolute;
left: 0;
top: 0;
background: rgb(51 51 51/50%);
width: 100%;
height: 100vh;
}
@media (max-width: 673px)
div#popup-form-contact-vr .content-popup-vr {
display: block;
}
.content-popup-vr {
background: #fff;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
width: 95%;
border-radius: 5px;
box-shadow: 0 0 14px 5px rgb(0 0 0/49%);
max-width: 600px;
display: flex;
}
.content-popup-vr .content-popup-div-vr {
width: 100%;
padding: 25px;
}
.content-popup-vr .close-popup-vr {
font-family: sans-serif;
width: 23px;
height: 23px;
background: #000;
position: absolute;
top: -10px;
right: -10px;
color: #fff;
text-align: center;
line-height: 23px;
font-size: 17px;
border-radius: 50%;
cursor: pointer;
}
</style>
<style type="text/css">
	body{background: #fff;}
</style>
<style type="text/css"></style>
    </head>
    <body>
<div id="print">
	<div id="hd_print">
		<h2 class="pull-left">Tốc Độ Việt - Dịch vụ Hosting, Tên miền, Máy chủ, Thiết kế Website</h2>
		<p class="pull-right"><a title="Tốc Độ Việt - Dịch vụ Hosting, Tên miền, Máy chủ, Thiết kế Website" href="https://tocdoviet.com/">https://tocdoviet.com</a></p>
	</div>
	<div class="clear"></div>
	<hr />
	<div id="content">
		<h1>Một số công dụng của htaccess</h1>
		<ul class="list-inline">
			<li>Thứ tư - 24/07/2013 05:04</li>
			<li class="hidden-print txtrequired"><em class="fa fa-print">&nbsp;</em><a title="In ra" href="javascript:;" onclick="window.print()">In ra</a></li>
			<li class="hidden-print txtrequired"><em class="fa fa-power-off">&nbsp;</em><a title="Đóng cửa sổ này" href="javascript:;" onclick="window.close()">Đóng cửa sổ này</a></li>
		</ul>
		<div class="clear"></div>
		<div id="hometext">
						<div class="pull-left imghome">
				<img alt="Một số công dụng của htaccess" src="https://tocdoviet.com/assets/blog/2013_07/htaccess.gif" width="100" class="img-thumbnail" />
			</div>
		</div>
		<div id="bodytext" class="clearfix">
			<strong>1. Ngăn chặn hotlink</strong><br  />Nhiều người copy ảnh từ server của bạn và đưa lên trang web của họ. Thêm vào .htaccess đoạn mã dưới đây sẽ giúp bạn ngăn chặn ảnh hiển thị trên website khác:<br  />#No hotlink<br  />RewriteEngine On<br  />RewriteCond %{HTTP_REFERER}!^$<br  />RewriteCond %{HTTP_REFERER}!^http://(www.)?tocdoviet.vn/[nc]<br  />RewriteRule .*.(gif|jpg|png)$ http://tocdoviet.vn/images/ads.png[nc]<br  /><br  /><strong>2. 301 Redirect</strong><br  />Nếu bạn chuyển domain, hoặc chỉ muốn chuyển một trang cũ về một trang mới và không muốn lo lắng về các kết quả search từ google, sử dụng đoạn mã sau<br  />Redirect 301 /d/file.html http://www.tocdoviet.vn/hosting<br  /><br  /><strong>3. Chuyển hướng từ tên miền cũ sang tên mới</strong><br  />Sử dụng đoạn mã dưới đây bạn có thể chuyển tất cả các link từ tên miền cũ sang tên miền mới:<br  />#Chuyển hướng từ tên miền cũ sang tên mới<br  />RewriteEngine On<br  />RewriteRule ^(.*)$ http://tocdoviet.vn/ $1[R=301,L]<br  /><br  /><strong>4. Tạo trang báo lỗi riêng</strong><br  />Bạn không muốn dùng các trang báo lỗi có sẵn của host, bạn có thể tạo các trang báo lỗi riêng và cấu hình vào file .htaccess như sau:<br  />ErrorDocument 401 /error/401.php<br  />ErrorDocument 403 /error/403.php<br  />ErrorDocument 404 /error/404.php<br  />ErrorDocument 500 /error/500.php<br  /><br  /><strong>5. Cấm IP truy cập</strong><br  />Nếu có 1 IP thường xuyên spam website của bạn, bạn có thể cấm IP đó như dòng 2, hoặc cấm 1 dải IP như dòng 3:<br  />allow f-rom all<br  />deny f-rom 113.190.183.138<br  />deny f-rom 113.190<br  /><br  /><strong>6. Đặt email mặc định cho server admin</strong><br  />Sử dụng đoạn mã sau:<br  />ServerSignature EMail<br  />SetEnv SERVER_ADMIN info@tocdoviet.vn<br  /><br  /><strong>7. Bảo vệ file</strong><br  />Đoạn mã dưới đây sẽ từ chối khi người dùng truy cập vào bất kỳ file nào và gửi về lỗi 403:<br  />#Protect .htaccess File<br  />order allow,deny<br  />deny f-rom all<br  /><br  /><br  /><strong>8. Đặt mã cho thư mục và file</strong><br  />Bạn có thể đặt mã &amp; quyền truy cập vào thư mục/file như sau:<br  /># Đặt mã cho thư mục<br  />resides<br  />AuthType basic<br  />AuthName &quot;Thư mục này đã được bảo vệ&quot;<br  />AuthUserFile /home/path/.htpasswd<br  />AuthGroupFile /dev/null<br  />Require valid-user<br  /># Đặt mã cho file<br  /><br  />AuthType Basic<br  />AuthName &quot;Prompt&quot;<br  />AuthUserFile /home/path/.htpasswd<br  />Require valid-user<br  /><br  /><br  /><strong>9. Đặt trang mặc định</strong><br  />Bạn có thể đặt trang web mặc định cho thư mục nào đó. Ví dụ đặt file about.html thay cho file index.html:<br  />#Đặt trang mặc định (index)<br  />DirectoryIndex about.html<br  /><br  /><strong>10. Nén file bằng cách bật Gzip</strong><br  />Bằng cách bật Gzip bạn có thể nén file từ server giúp cho việc tải trang nhanh hơn<br  />AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript<br  />BrowserMatch ^Mozilla/4 gzip-only-text/html<br  />BrowserMatch ^Mozilla/4.0[678] no-gzip<br  />BrowserMatch bMSIE !no-gzip!gzip-only-text/html<br  /><br  /><strong>11. Bỏ &quot;category&quot; ở URL</strong><br  />Để chuyển url từ: http://tocdoviet.vn/announcements/ về -&gt; http://tocdoviet.vn/announcements.php, bạn chỉ cần thêm vào file.htaccess đoạn mã sau<br  />RewriteRule ^announcements/(.+)$ http://tocdoviet.vn/ $1[R=301,L]<br  /><br  /><strong>12. Bỏ phần đuôi file ở URL</strong><br  />Bạn mới lập trình php và không muốn hiện .php ở url, hãy thêm đoạn code sau:<br  />RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]<br  /><br  /><strong>13. Thêm / vào cuối URL</strong><br  />Một vài bộ máy tìm kiếm (như Yahoo)tự động bỏ dấu / ở cuối url. Website của bạn cũng có thể được truy cập có hoặc không có dấu / ở sau cùng url. Điều này không tốt với các bộ máy tìm kiếm (sẽ bị coi là duplicated content). Thêm đoạn mã dưới đây vào .htaccess để giải quyết vấn đề đó:<br  />#Thêm / vào cuối URL<br  />RewriteBase /<br  />RewriteCond%{REQUEST_FILENAME} !-f<br  />RewriteCond %{REQUEST_URI} !#<br  />RewriteCond %{REQUEST_URI}!(.*)/$<br  />RewriteRule ^(.*)$ http://tocdoviet.vn/ $1[L,R=301]<br  /><br  /><strong>14. Bỏ www ở URL</strong><br  />Nếu bạn muốn chuyển mọi truy cập từ http://www.tocdoviet.vn thành http://tocdoviet.vn, thêm đoạn mã sau vào file .htaccess:<br  />RewriteEngine On<br  />RewriteBase /<br  />RewriteCond %{HTTP_HOST}!^tocdoviet.vn$ [NC]<br  />RewriteRule ^(.*)$ http://tocdoviet.vn/ $1[L,R=301]<br  /><br  /><strong>15. Thêm www vào URL</strong><br  />Tất nhiên nếu bạn muốn ngược lại &quot;14&quot; bạn có thể dùng đoạn mã sau:<br  />RewriteEngine On<br  />RewriteBase /<br  />RewriteCond %{HTTP_HOST}!^www.tocdoviet.vn$[NC]<br  />RewriteRule ^(.*)$ http://www.tocdoviet.vn/$1[L,R=301]<br  /><br  /><strong>16. Không cho &quot;browse&quot; thư mục</strong><br  />Để ngăn chặn truy cập vào tên file trong thư mục nào đó (ví dụ thư mục plugins của wordpress), thêm đoạn mã sau vào file.htacess:<br  />Options All -Indexes<br  />Nếu bạn muốn cho phép browse thư mục bạn chỉ cần đổi lại là: Options All +Indexes<br  /><br  /><br  />
		</div>
	</div>
	<div id="footer" class="clearfix">
		<div id="url">
			<strong>URL của bản tin này: </strong><a href="https://tocdoviet.com/blog/savefile/Tai-lieu-SEO/Mot-so-cong-dung-cua-htaccess-130.html" title="Một số công dụng của htaccess">https://tocdoviet.com/blog/savefile/Tai-lieu-SEO/Mot-so-cong-dung-cua-htaccess-130.html</a>

		</div>
		<div class="clear"></div>
		<div class="copyright">
			&copy; Tốc Độ Việt - Dịch vụ Hosting, Tên miền, Máy chủ, Thiết kế Website
		</div>
		<div id="contact">
			<a href="mailto:loc.thb@bazan.vn">loc.thb@bazan.vn</a>
		</div>
	</div>
</div>
        <div id="timeoutsess" class="chromeframe">
            Bạn đã không sử dụng Site, <a onclick="timeoutsesscancel();" href="https://tocdoviet.com/#">Bấm vào đây để duy trì trạng thái đăng nhập</a>. Thời gian chờ: <span id="secField"> 60 </span> giây
        </div>
        <div id="openidResult" class="nv-alert" style="display:none"></div>
        <div id="openidBt" data-result="" data-redirect=""></div>
        <div id="button-contact-vr" class=""><div id="gom-all-in-one"><div id="zalo-vr" class="button-contact"><div class="phone-vr"><div class="phone-vr-circle-fill"></div><div class="phone-vr-img-circle">
<a target="_blank" href="https://zalo.me/0888037777">
<img src="https://tocdoviet.com/themes/default/images/zalo.png">
</a></div></div></div><div id="phone-vr" class="button-contact"><div class="phone-vr"><div class="phone-vr-circle-fill"></div><div class="phone-vr-img-circle">
<a href="tel:0888037777">
<img src="https://tocdoviet.com/themes/default/images/phone.png">
</a></div></div></div></div></div><div id="popup-form-contact-vr"><div class="bg-popup-vr"></div><div class="content-popup-vr" id="loco-" style=" "><div class="content-popup-div-vr"></div><div class="close-popup-vr">x</div></div></div><div id="popup-showroom-vr"><div class="bg-popup-vr"></div><div class="content-popup-vr" id="loco-" style=" "><div class="content-popup-div-vr"></div><div class="close-popup-vr">x</div></div></div>

<div id="run_cronjobs" style="visibility:hidden;display:none;"><img alt="cron" src="/index.php?second=cronjobs&amp;p=v2sV44F3" width="1" height="1" /></div>
<script src="https://tocdoviet.com/assets/js/jquery/jquery.min.js"></script>
<script>var nv_base_siteurl="/",nv_lang_data="vi",nv_lang_interface="vi",nv_name_variable="nv",nv_fc_variable="op",nv_lang_variable="language",nv_module_name="blog",nv_func_name="savefile",nv_is_user=0, nv_my_ofs=-4,nv_my_abbr="EDT",nv_cookie_prefix="nv4",nv_check_pass_mstime=1738000,nv_area_admin=0,nv_safemode=0,theme_responsive=1,nv_recaptcha_ver=2,nv_recaptcha_sitekey="",nv_recaptcha_type="image",XSSsanitize=1;</script>
<script src="https://tocdoviet.com/assets/js/language/vi.js"></script>
<script src="https://tocdoviet.com/assets/js/DOMPurify/purify3.js"></script>
<script src="https://tocdoviet.com/assets/js/global.js"></script>
<script src="https://tocdoviet.com/assets/js/site.js"></script>
<script src="https://tocdoviet.com/themes/default/js/news.js"></script>
<script src="https://tocdoviet.com/themes/default/js/main.js"></script>
<script src="https://tocdoviet.com/themes/default/js/custom.js"></script>
<script type="application/ld+json">
        {
            "@context": "https://schema.org",
            "@type": "Organization",
            "url": "https://tocdoviet.com",
            "logo": "https://tocdoviet.com/assets/images/logo.png"
        }
        </script>
<script src="https://tocdoviet.com/themes/default/js/bootstrap.min.js"></script>
</body>
</html>