
1.1. .htaccess l g
.htaccess l một file cấu hnh sử dụng cho cc web server chạy Apache. .htaccess dng để thiết lập cc ty chọn: thực thi hay loại bỏ cc chức năng, tnh năng của Apache
1.2. nghĩa k hiệu định nghĩa trong .htaccess
# : cho php server bỏ qua dng ny
[F] : Forbidden, hướng dẫn server trả về lỗi 403 cho client
[L] : Last rule, hướng dẫn server ngừng ghi lại sau khi một chỉ thị đ được xử l
[N] : Next, chỉ dẫn cho Apache trả về luật rewrite cho tới khi tất cả cc chỉ thị rewrite được hon tất.
[G]: Gone, chỉ dẫn server chuyển thng điệp Gone
[P]: Proxy, chỉ dẫn server sử dụng cc request cung cấp bởi mod_proxy
[C]: Chain, chỉ dẫn server gắn luật trước với luật sau n
[R]: Redirect, hướng dẫn Apache đưa ra một chuyển hướng
[NC]: No case, xc định bất cứ trường hợp no lin quan tới n l v l (Khng thể xảy ra)
[PT]: Pas Through: chỉ dẫn mod_rewrite để vượt qua cơ chế ghi lại URL cho cc xử l xa hơn
[OR]: Or, l c php logic bnh thường (biểu thức kết hợp đng khi một trong hai biểu thức con của n đng)
[NE]: No Escape: hướng dẫn server lọc đầu ra
[NS]: No Subresquest: hướng dẫn server giữ chỉ thị nếu l một request con từ bn trong
[QSA]: gắn thm chuỗi truy vấn vo cuối URL
[S=x]: Skip: chỉ dẫn server dừng lại x luật
[E=[/COLOR]variable:value]: Environment Variale: chỉ dẫn server thiết lập gi trị ti nguyn
[T=MIME-type]: Mime Type: m tả loại mime của ti nguyn đch
[]: xc định một tập cc k tự trong đ bất cứ k tự no c trong ngoặc xuất hiện sẽ được match
[]+: tập cc k tự trong đ bất cứ kết hợp no với n cũng được match
[a-z] : match với tất cả cc k tự từ a-z, theo bảng chữ ci. C thể c thm: [a-zA-Z]
a{n}: xc định số k tự sẽ mở rộng cng với k tự đầu, tức l khi match được k tự đầu sẽ lấy thm bao nhiu k tự tiếp theo. V dụ: x

a{n,} : như a{n} nhưng c thể lấy 3 hoặc nhiều hơn
a{n,m}: như a{n} nhưng sẽ lấy trong khoảng từ n tới m
(): nhm cc k tự lại với nhau, xem chng như 1 đơn vị đơn lẻ
^: ghi ch bắt đầu chuỗi regex
$: ghi ch kết thc chuỗi regex
? : cho php chọn lựa k tự.V dụ: monzas? sẽ match với monza hoặcmonzas
! : m tả một phủ định, sẽ match với tất cả thứ g khc với cc k tự sau !
. : thể hiện cho bất cứ k tự đơn no
+: match với một hoặc nhiều k tự
*: match với 0 hoặc nhiều k tự
|: php hoặc logic
\: thm vo trước cc k tự đặc biệt để c thể sử dụng chng như cc k tự bnh thường
.* : khng c k tự no hoặc nhiều k tự bất kỳ
^$: định nghĩa một chuỗi rỗng
^.*$: sử dụng để match mọi thứ
[^/.]: định nghĩa 1 k tự l / hoặc .
[^/.]+: định nghĩa bất cứ số lượng k tự no chứa / hoặc .
http://: l một chuỗi bnh thường
^domain.*: định nghĩa một chuỗi bắt đầu với domain
^domain\.com$: xc định sự mở rộng của chuỗi domain.com
-d: kiểm tra nếu chuỗi l một directory
-f: kiểm tra nếu một chuỗi l một file
-s: kiểm tra nếu file trong chuỗi kiểm tra c 1 gi trị khc 0
1.3. M redirect
301 Move permanently
302 Move temporarily
403 Forbidden
404 Not found
410 Gone
1.4. Cch sử dụng .htaccess
Tạo file .htaccess (ch đy l tn đầy đủ, khng phải l phần mở rộng), tiến hnh cc thiết lập cấu hnh trong file v đặt ở trong thư mục mong muốn thực hiện cc cấu hnh đ.
V dụ:
AuthUserFile /path/to/password/file/.htpasswd
AuthType Basic
require valid-user
ErrorDocument 401 /error_pages/401.html
AddHandler server-parsed .html
Ch :
- Upload file .htaccess ở chế độ ASCII thay v chế độ BINARY hay cc chế độ khc do cơ chế chuyển dữ liệu ở cc chế độ l khc nhau.
- Việc cấp quyền truy cập, sử dụng v thực thi file .htaccess c thể gy ra lỗi, ci đặt quyền 755 hoặc quyền thực thi với file
- Comment lại cc thng tin cấu hnh quan trọng để dễ dng cho người tiếp quản sau ny hoặc cho chnh bản than khi phải cấu hnh lại hoặc khắc phục sự cố no đ
2. Những cấu hnh cần thiết
2.1. Enable basic rewriting
Server c thể khng bật chế độ mod_rewite mặc định, để đảm bảo chế độ ny được bật, thm vo file .htaccess tại thư mục root:
RewriteEngine on
Xem về Symbolic links tại:http://en.wikipedia.org/wiki/Symbolic_link. Để chế độ ny hoặc động, tnh năng: AllowOverride Options cần được enable.
Options +FollowSymLinks
Đối với cc chỉ thị cần tnh năng AllowOverride để thực thi như: FollowSymlinks, Khi cần enable tnh năng ny tại một thư mục no đ, ta thm vo .htaccess (C thể cấu hnh tại file server để p dụng ton bộ):
AllowOverride Options
Khng phải mọi hệ thống đều thch định dạng .htaccess, c thể thay đổi tn ny (thực hiện trn file cấu hnh của server):
AccessFileName ht.access
Order deny,allow
Deny from all
Tiết kiệm thời gian v nỗ lực định nghĩa lại cc luật lặp lại cho nhiều host ảo với chỉ 1 file httpd.conf, để đơn giản hơn ta cấu hnh .htaccess kế thừa tập luật từ httpd.conf
3.1. Tăng hiệu năng thng qua AllowOverride
Việc cấu hnh AllowOverride ở thư mục gốc, server sẽ phải tm kiếm ở tất cả cc thư mục để xem nơi no .htaccess tồn tại, điều ny lm chậm tốc độ xử l. Để hạn chế điều ny, disable chế độ AllowOverride tại thư mục gốc v bật ln ở những nơi cần dng, để disable:
AllowOverride None
AddDefaultCharset utf-8
php_value zlib.output_compression 16386
ServerSignature Off
SetEnv TZ America/Washington
SetEnv SERVER_ADMINdefault@domain.com
3.7. Tăng tốc độ duyệt site bằng việc enable file caching
Header set Cache-Control "max-age=2592000"
# cache text, css, and javascript files for one week
Header set Cache-Control "max-age=604800"
# cache html and htm files for one day
Header set Cache-Control "max-age=43200"
# implement minimal caching during site development
Header set Cache-Control "max-age=5"
# explicitly disable caching for scripts and other dynamic files
Header unset Cache-Control
# alternate method for file caching
ExpiresActive On
ExpiresDefault A604800 # 1 week
ExpiresByType image/x-icon A2419200 # 1 month
ExpiresByType application/x-javascript A2419200 # 1 month
ExpiresByType text/css A2419200 # 1 month
ExpiresByType text/html A300 # 5 minutes
# disable caching for scripts and other dynamic files
ExpiresActive Off
- *Convert common time intervals into seconds:
- 300 = 5 minutes
- 2700 = 45 minutes
- 3600 = 1 hour
- 54000 = 15 hours
- 86400 = 1 day
- 518400 = 6 days
- 604800 = 1 week
- 1814400 = 3 weeks
- 2419200 = 1 month
- 26611200 = 11 months
- 29030400 = 1 year = never expires
3.8. Ci đặt ngn ngữ v kiểu m ha mặc định
# set the default language
DefaultLanguage en-US
# set the default character set
AddDefaultCharset UTF-8
3.9. M tả MIME
MIME types l tập cc phần mở rộng của file, server cần biết tham số ny để biết n đang thao tc với loại file no. Sử dụng AddType để thm một MIME, tham số tiếp theo l loại MIME v cuối cng l phần mở rộng của file. V dụ với file MP3 hoặc SWF:
AddType application/x-shockwave-flash .swf
AddType video/x-flv .flv
AddType image/x-icon .ico
Danh sch cc MIME v loại file tương ứng:
AddType text/plain .txt
AddType text/richtext .rtx
AddType text/tab-separated-values .tsv
AddType text/x-setext .etx
AddType text/x-server-parsed-html .shtml .sht
AddType application/macbinhex-40 .hqx
AddType application/netalivelink .nel
AddType application/netalive .net
AddType application/news-message-id
AddType application/news-transmission
AddType application/octet-stream .bin .exe
AddType application/oda .oda
AddType application/pdf .pdf
AddType application/postscript .ai .eps .ps
AddType application/remote-printing
AddType application/rtf .rtf
AddType application/slate
AddType application/zip .zip
AddType application/x-mif .mif
AddType application/wita
AddType application/wordperfect5.1
AddType application/x-csh .csh
AddType application/x-dvi .dvi
AddType application/x-hdf .hdf
AddType application/x-latex .latex
AddType application/x-netcdf .nc .cdf
AddType application/x-sh .sh
AddType application/x-tcl .tcl
AddType application/x-tex .tex
AddType application/x-texinfo .texinfo .texi
AddType application/x-troff .t .tr .roff
AddType application/x-troff-man .man
AddType application/x-troff-me .me
AddType application/x-troff-ms .ms
AddType application/x-wais-source .src
AddType application/x-bcpio .bcpio
AddType application/x-cpio .cpio
AddType application/x-gtar .gtar
AddType application/x-shar .shar
AddType application/x-sv4cpio .sv4cpio
AddType application/x-sv4crc .sv4crc
AddType application/x-tar .tar
AddType application/x-ustar .ustar
AddType application/x-director .dcr
AddType application/x-director .dir
AddType application/x-director .dxr
AddType application/x-onlive .sds
AddType application/x-httpd-cgi .cgi
AddType image/gif .gif .GIF
AddType image/ief .ief
AddType image/jpeg .jpeg .jpg .jpe .JPG
AddType image/tiff .tiff .tif
AddType image/x-cmu-raster .ras
AddType image/x-portable-anymap .pnm
AddType image/x-portable-bitmap .pbm
AddType image/x-portable-graymap .pgm
AddType image/x-portable-pixmap .ppm
AddType image/x-rgb .rgb
AddType image/x-xbitmap .xbm
AddType image/x-xpixmap .xpm
AddType image/x-xwindowdump .xwd
AddType audio/basic .au .snd
AddType audio/x-aiff .aif .aiff .aifc
AddType audio/x-wav .wav
AddType audio/x-pn-realaudio .ram
AddType audio/x-midi .mid
AddType video/mpeg .mpeg .mpg .mpe
AddType video/quicktime .qt .mov
AddType video/x-msvideo .avi
AddType video/x-sgi-movie .movie
AddType message/external-body
AddType message/news
AddType message/partial
AddType message/rfc822
AddType multipart/alternative
AddType multipart/appledouble
AddType multipart/digest
AddType multipart/mixed
AddType multipart/parallel
AddType x-world/x-vrml .wrl
# AddType 'text/html; charset=UTF-8' html
AddDefaultCharset UTF-8
DefaultLanguage en-US
Options -ExecCGI -Indexes -All
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK|OPTIONS|HEAD) RewriteRule .* - [F]
Script PUT /cgi-bin/upload.cgi
Script GET /cgi-bin/download.cgi
Action image/png /cgi-bin/png-script.cgi

- Mask
4.1. Ngăn cản truy cập file .htaccess
Khi người dng cố tnh truy nhập file .htaccess sẽ trả về lỗi 403, c nhiều cch để cấu hnh, c thể cấu hnh file với CHMOD l 644 hoặc thm đoạn m sau:
order allow,deny
deny from all
Để chặn truy nhập vo một file đặc biệt no đ, thm đoạn m sau vo file .htaccess, giả sử l file secretfile.jpg
order allow,deny
deny from all
Order Allow,Deny
Deny from all
Đảm bảo người dng khng c đủ quyền khng thể xem ton bộ trang web dưới dạng Directory listing.
Options All Indexes
Options All +Indexes
IndexIgnore *
IndexIgnore *.wmv *.mp4 *.avi *.etc
C thể thay v sử dụng trang index một cch mặc định, ta cấu hnh cho server nhận một file khc c chức năng tương tự như file index (ở đyl business.html)
DirectoryIndex business.html
DirectoryIndex filename.html index.cgi index.pl default.htm
Để tăng cường tnh bảo mật, việc ngụy trang cho ngn ngữ kịch bản bằng việc thay đổi phần mở rộng cũng l một yếu tố cần xt đến:
AddType application/x-httpd-php .foo
# serve foo files as cgi files
AddType application/x-httpd-cgi .foo
order deny,allow
deny from all
allow from 192.168.0.0/33
Cấu hnh cho php cc truy cập ngoại trừ truy cập từ địa chỉ: x.y.z.v v từ domain.com
order allow,deny
allow from all
deny from x.y.z.v
deny from .*domain.com.*
order deny,allow
deny from all
allow from x.y.z.v
allow from .*domain.com.*
RewriteEngine on
RewriteCond %{HTTP_REFERER} abc.com [NC,OR]
RewriteCond %{HTTP_REFERER} xyz.com [NC,OR]
RewriteRule .* - [F]
C nhiều phương php để block một dải địa chỉ IP bằng cch cấu hnh .htaccess. Cch thức đầu tin c thể sử dụng s CIDR (Classess Inter-Domain Routing) của dải IP, cch ny hiệu quả để block cc mega-spammer như RIPE, Optinet,
order allow,deny
allow from all
deny from 10.1.0.0/16
deny from 80.0.0/8
order deny,allow
deny from all
allow from 10.1.0.0/16
allow from 80.0.0/8
order allow,deny
allow from all
deny from 99.88.77.66
deny from 99.88.77.*
deny from 99.88.*.*
deny from 99.*.*.*
order deny,allow
deny from all
allow from 99.88.77.66
allow from 99.88.77.*
allow from 99.88.*.*
allow from 99.*.*.*
Block:
deny from 99.88.77.66 11.22.33.44
# block three ranges of IP addresses
deny from 99.88 99.88.77 11.22.33
allow from 99.88.77.66 11.22.33.44
# allow three ranges of IP addresses
allow from 99.88 99.88.77 11.22.33
C một số luật khc c thể sử dụng:
deny from 99.1.0.0/255.255.0.0
# block a single domain
deny from 99.88.77.66
# block domain.com but allow sub.domain.com
order deny,allow
deny from domain.com
allow from sub.domain.com
Mục tiu nhằm gip cc quản trị vin ngăn cản cc website bn ngoi sử dụng trực tiếp cc hnh ảnh, nội dung, link, từ website của mnh. V dạng ny lm tốn băng thng.
Sử dụng chế độ ny khi đ kch hoạtmod_rewrite.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?domain.com/.*$ [NC]
RewriteRule .*.(gif|jpg)$http://www.domain.com/eatme.jpg[R,NC,L]
RewriteRule .*.(gif|jpg)$ - [F,L]
RewriteCond %{HTTP_REFERER} !^http://(www.)?goodsite.com/.*$ [NC]
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
RewriteCond %{HTTP_USER_AGENT} ^Botmailto:craftbot@yahoo.com[OR]
RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR]
RewriteCond %{HTTP_USER_AGENT} ^Custo [OR]
RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR]
RewriteCond %{HTTP_USER_AGENT} ^Download Demon [OR]
RewriteCond %{HTTP_USER_AGENT} ^eCatch [OR]
RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [OR]
RewriteCond %{HTTP_USER_AGENT} ^Express WebPictures [OR]
RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [OR]
RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [OR]
RewriteCond %{HTTP_USER_AGENT} ^FlashGet [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetRight [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [OR]
RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [OR]
RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [OR]
RewriteCond %{HTTP_USER_AGENT} ^GrabNet [OR]
RewriteCond %{HTTP_USER_AGENT} ^Grafula [OR]
RewriteCond %{HTTP_USER_AGENT} ^HMView [OR]
RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Image Stripper [OR]
RewriteCond %{HTTP_USER_AGENT} ^Image Sucker [OR]
RewriteCond %{HTTP_USER_AGENT} Indy Library [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR]
RewriteCond %{HTTP_USER_AGENT} ^Internet Ninja [OR]
RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR]
RewriteCond %{HTTP_USER_AGENT} ^JOC Web Spider [OR]
RewriteCond %{HTTP_USER_AGENT} ^larbin [OR]
RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mass Downloader [OR]
RewriteCond %{HTTP_USER_AGENT} ^MIDown tool [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mister PiX [OR]
RewriteCond %{HTTP_USER_AGENT} ^Navroad [OR]
RewriteCond %{HTTP_USER_AGENT} ^NearSite [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetAnts [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Net Vampire [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetZIP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Octopus [OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline Explorer [OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline Navigator [OR]
RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} ^Papa Foto [OR]
RewriteCond %{HTTP_USER_AGENT} ^pavuk [OR]
RewriteCond %{HTTP_USER_AGENT} ^pcBrowser [OR]
RewriteCond %{HTTP_USER_AGENT} ^RealDownload [OR]
RewriteCond %{HTTP_USER_AGENT} ^ReGet [OR]
RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger [OR]
RewriteCond %{HTTP_USER_AGENT} ^SmartDownload [OR]
RewriteCond %{HTTP_USER_AGENT} ^SuperBot [OR]
RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Surfbot [OR]
RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [OR]
RewriteCond %{HTTP_USER_AGENT} ^Teleport Pro [OR]
RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [OR]
RewriteCond %{HTTP_USER_AGENT} ^Web Image Collector [OR]
RewriteCond %{HTTP_USER_AGENT} ^Web Sucker [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebAuto [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebCopier [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebFetch [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebGo IS [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebLeacher [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebReaper [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebSauger [OR]
RewriteCond %{HTTP_USER_AGENT} ^Website eXtractor [OR]
RewriteCond %{HTTP_USER_AGENT} ^Website Quester [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebStripper [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Wget [OR]
RewriteCond %{HTTP_USER_AGENT} ^Widow [OR]
RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule ^.* - [F,L]
Thay v gửi một thng bo thn thiện, c thể gửi lại mộ website:
RewriteRule ^.*$http://www.hellish-website.com[R,L]
RewriteRule ^.*$http://english-61925045732.spampoison.com[R,L]
RewriteRule !^http://[^/.].yourdomain.com.* - [F,L]
RewriteCond %{HTTP_REFERER} ^http://.*spamsite.*$ [NC]
RewriteRule .*http://www.differentspamsite.com[R]
# redirect all requests from spamsite to an image of something at differentspamsite
RewriteCond %{HTTP_REFERER} ^http://.*spamsite.*$ [NC]
RewriteRule .*http://www.differentspamsite/something.jpg[R]
# redirect traffic from a certain address or range of addresses to another site
RewriteCond %{REMOTE_ADDR} 192.168.10.*
RewriteRule .*http://www.differentspamsite.com/index.html[R]
Đặt password bảo vệ l một biện php bảo vệ nội dung website v chỉ cho php người dng nội bộ c thể truy nhập nội dung.
Được hỗ trợ bởi Apache. Gip giới hạn người dng trong những khu vực khc nhau của một website.
Khi một thư mục được đặt password th ton bộ thư mục con v file trong thư mục sẽ được đặt password như vậy.
Nội dung file .htaccess để thư mục chứa n được bảo vệ bởi mật khẩu:
username:encryptedpassword
fred_smith
Tham khảo trang sau (tạo password bảo vệ thư mục):
http://www.thejackol.com/scripts/htpasswdgen.php
AuthType Basic
AuthName "Prompt"
AuthUserFile /home/path/.htpasswd
Require valid-user
# password-protect multiple files
AuthType basic
AuthName "Development"
AuthUserFile /home/path/.htpasswd
Require valid-user
# password-protect the directory in which this htaccess rule resides
AuthType basic
AuthName "This directory is protected"
AuthUserFile /home/path/.htpasswd
AuthGroupFile /dev/null
Require valid-user
# password-protect directory for every IP except the one specified
# place in htaccess file of a directory to protect that entire directory
AuthType Basic
AuthName "Personal"
AuthUserFile /home/path/.htpasswd
Require valid-user
Allow from 99.88.77.66
Satisfy Any
Cch thức ny đảm bảo đặt CHMOD cho cc loại file xc định.
# remember to never set CHMOD 777 unless you know what you are doing
# files requiring write access should use CHMOD 766 rather than 777
# keep specific file types private by setting their CHMOD to 400
chmod .htpasswd files 640
chmod .htaccess files 644
chmod php files 600
Ngụy trang tất cả cc file v coi như file .php
ForceType application/x-httpd-php
SetHandler application/x-httpd-php
LimitRequestBody 10240000
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
Options ExecCGI
SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "domain.tld"
ErrorDocument 403https://domain.tld
# require SSL without mod_ssl
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
5.1. Kiểm tra URL
CheckSpelling On
Cấu hnh ny rất hữu ch v n đưa ra lỗi cho người truy cập website một cch thn thiện, gip cho chủ website hiện thị cc thng bo lỗi theo cch ring.
ErrorDocument 400 /errors/400.html
ErrorDocument 401 /errors/401.html
ErrorDocument 403 /errors/403.html
ErrorDocument 404 /errors/404.html
ErrorDocument 500 /errors/500.html
Điều ny hữu ch đối với cc file multi media
AddType application/octet-stream .avi
AddType application/octet-stream .mpg
AddType application/octet-stream .wmv
AddType application/octet-stream .mp3
C thể p dụng với cc định dạng khc (Xem thm phần: 3.9)
Một số trường hợp cần hiển thị m nguồn của một file thay v thực thi chng, sử dụng:
RemoveHandler cgi-script .pl .py .cgi
5.5. Redirect người dng tới một site tạm thời khi pht triển hoặc sửa lỗi
Trong qu trnh pht triển, bảo tr hay sửa chữa website, bạn khng muốn khch hng viếng thăm, cấu hnh dưới sẽ gip chuyển hướng người dng tới một site khc trong khi quản trị vin vẫn c khả năng truy nhập đầy đủ (x.x.x.x l IP của quản trị):
ErrorDocument 403http://www.alternate-site.com
Order deny,allow
Deny from all
Allow from x.x.x.x
RewriteCond %{TIME_HOUR} ^12$
RewriteRule ^.*$ - [F,L]
# prevent access throughout the afternoon
RewriteCond %{TIME_HOUR} ^(12|13|14|15)$
RewriteRule ^.*$ - [F,L]
Đối với tất cả cc loại redirect sử dụng mode_rewrite cần enable chế độ: RewriteEngine.
RewriteEngine on
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www.domain.tld$ [NC]
RewriteRule ^(.*)$http://domain.tld/$1[R=301,L]
RewriteEngine On
RewriteRule ^(.*)$http://www.new-domain.com/$1[R=301,L]
Giả sử một request c chứa string: some-string, ta sẽ chuyển request ny tới trang:http://some-string.com
RewriteRule ^some-stringhttp://www.some-string.com[R]
AliasMatch ^/director(y|ies) /www/docs/target
# map URL variations to the same directory on a different server
RedirectMatch ^/[dD]irector(y|ies)http://domain.com
Redirect một site đầu vo với trạng thi 301:
redirect 301 /http://www.domain.com/
redirect 301 /current/currentfile.htmlhttp://www.newdomain.com/new/new

Thủ Thuật Hay
470 Blog posts
- Content Intelligence Market with Dynamics, Segments, and Forecast by 2032
Content Intelligence Market is rising as businesses leverage AI and analytics to optimize content creation, personalization, and strategy.
- soporte informatico barcelona
TANCRA Systems está especializada en reparación y mantenimiento de equipos informáticos. Proporcionamos diferentes soluciones adaptadas a las diferentes necesidades de nuestros clientes. Estos son nuestros servicios:
- What are the benefits of multi-currency system?
This is especially important for multinational corporations that need to present accurate consolidated financial statements.
- Innovate to Dominate: How Enterprise AI Market is Reshaping Industries
The Enterprise AI Market has valued at US$ 6141.5 Mn in 2022. The Global Enterprise AI Market size is estimated to grow at a CAGR of 48.7% over the forecast period.
- Surfex India Your Partner for High Performance Robotic Shot Peening Solutions
Whether you’re upgrading existing processes or stepping into automated shot peening for the first time, Surfex India is here to help you achieve success.
- Wireless Bridge Market Size, Share, and Forecast to 2031 | Market Strides
Uncover the latest trends and insights in the Wireless Bridge market with our comprehensive market size and forecast for 2023-2031. Learn about the different types of Wireless Bridge and their impact on the industry, as well as the competitive landscape and key suppliers.
- Satellite Broadband Communication in Public Safety Market Size, Analytical Overview, Growth Factors, Demand, Trends and
Satellite Broadband Communication in Public Safety Market Size, Analytical Overview, Growth Factors, Demand, Trends and Forecast by 2031
- Urinalysis Market Size, Share, Industry Report, Revenue Trends - 2024-2032
Urinalysis is a common diagnostic test that examines the physical, chemical, and microscopic properties of urine. It can provide valuable information about a person's overall health and help detect various medical conditions such as urinary tract infections, kidney disease, diabetes,
- Driving Innovation: Trends in the CMOS Power Amplifier Market
The CMOS Power Amplifier Market is expected to register a CAGR of 8.3% from 2025 to 2031, with a market size expanding from US$ XX million in 2024 to US$ XX Million by 2031.
- Projector Brightness Requirements with Laser Projectors
In this blog, we will explore how laser projectors meet modern brightness demands, what factors influence brightness requirements, and why this technology is becoming the standard across industries in 2025.