Tao dia chi web dep voi modRewrite trong Apache
- Bai viet tu: mathforums.hcmup.edu.vn
- Tham khao chi tiet: Module mod_rewrite - URL Rewriting Engine
(modRewrite la mot module tuyet voi cua Apache. Bai nay se chi mot so ap dung cua modRewrite de dua nghich voi cac dia chi web)
Cac chi thi cua modRewrite co the dat trong httpd.conf (phan cau hinh server, virtual host hoac directory deu duoc) hoac dat trong .htaccess deu duoc.
Cu phap don gian cua no la RewriteRule tim-cai-gi thay-the-bang-cai-gi, neu muon tim hieu them ban co the tham khao Apache manual
De bat modRewrite trong .htaccess ban dung dong RewriteEngine On. Neu bi bao loi 500 thi co nghia la host cua ban khong cai dat module nay.
De cai dat modRewrite, ban co the tham khao cac bai viet ve cai dat Apache.
1. Doi phan mo rong
Thay vi dung index.php thi ban co the goi bang index.4u ma khong can doi ten index.php thanh index.4u
Duoi day la doan ma minh hoa. Ma lenh:
RewriteEngine on RewriteRule ^(.*)\.4u /$1.php [QSA]
QSA (Query String Appended) y noi la phan sau dau ? van duoc them vao va giu nguyen.
2. Khong can query string
Gia du ban muon /index.php?act=view&cid=8&id=123 tu dong thay bang /view/8/123/ chang han (theo thi du cua ban), thi ta dung .htaccess nhu sau:
Ma lenh RewriteEngine on
RewriteRule ^view/([0-9]+)/([0-9]+)/$ /index.php?act=view&cid=$1&id=$2
Giai thich so qua: dong dau tien bat RewriteEngine, dong thu 2 co dang RewriteRule tim thay-the, chuoi tim cua ta la ^view/([0-9]+)/([0-9]+)/$ voi dau ^ cho biet la vi tri dau tien, $ la vi tri cuoi, ([0-9]+) la mot chuoi chi gom cac ki tu 0 den 9 (hay noi cach khac, la 1 con so). Trong phan thay-the cung khong co gi dac biet, ngoai tru $1 va $2 la cac gia tri tim thay ung voi 2 cap ngoac ([0-9]+) trong chuoi tim.
Tuong tu, ban co the them cac RewriteRule khac theo y thich.
Chuc ban thanh cong!
Comments
Chao ban.
"Neu bi bao loi 500 thi co nghia la host cua ban khong cai dat module nay."
Vay lam sao de cai dat module nay o localhost?
Minh muon test chuc nang cua .htaccess o local nhung khong biet phai khoi dong nhu the nao. Giup minh voi nhe.
Kich hoat module rewrite
Kich hoat module rewrite
- Vao folder da cai dat Apache, mo file conf/httpd.conf
- Dung chuc nang search, tim dong co chuoi 'mod_rewrite'
- Uncomment (bo dau # dau dong)
- Luu file lai
- Khoi dong lai Apache
Edit file .htaccess: Mo bang editor nao cung duoc, ngay ca notepad.
The Hong,
Delete visited website on the Address bar
Co' ba.n na`o bie^'t delete the visited website on the address bar, username ..
usually they have done by click on "Tool" , then select "Internet Option" , select "General" tab, click on "Delete File" button, click on "Clear History" button....
Toi da~ la`m du'ng nhu* tre^n, but sometime in the regedit menu stored some usernames ...
C'am on* toila.net nhie^`u
Duy2007
doi dia chi
em tao web tren ucoz, bay gio muon doi dia chi khac duoc hok, vi du nhu bam a2ontop.com thi vao duoc a2ontop.ucoz.com hok?
giup em voi!
Post new comment