- Xu
- 770,178,370
Bài viết: 4162 



.htaccess là tiện ích dành riêng cho Apache Server, để rewirte được Url bạn cần convert sang ruler của nginx.
Dưới đây là những tiện ích online convert sang rewrite ruler của nginx.
Các trang web convert .htacess online:
http://winginx.com/en/htaccess
http://www.anilcetin.com
https://labs.gidix.de/nginx
Riêng rewrite cho link file hoặc ảnh trên nginx thì các bạn làm theo cú pháp sau:
Bạn muốn rewrite cho domain nào trên VPS, Server thì chèn code đã convert vào file domain.com.conf của domain đó trong thư mục etc/nginx/conf.d.
Demo cho các bạn tham khảo site: nhoc.vn
Sau đó restart lại VPS, Server của bạn để việc thay đổi có hiệu lực.
Lệnh restart VPS - Server nginx:
Demo nginx chạy url rewrite:
Nghe Nhạc Online
Hài Tết Mới Nhất
Dưới đây là những tiện ích online convert sang rewrite ruler của nginx.
Các trang web convert .htacess online:
http://winginx.com/en/htaccess
http://www.anilcetin.com
https://labs.gidix.de/nginx
Riêng rewrite cho link file hoặc ảnh trên nginx thì các bạn làm theo cú pháp sau:
Mã:
location ~ \.(gif|jpg|png) {
try_files $uri @img_proxy;
}
location @img_proxy {
rewrite ^/img/(.*)/(.*).jpg$ /img.php?id=$1;
}
Bạn muốn rewrite cho domain nào trên VPS, Server thì chèn code đã convert vào file domain.com.conf của domain đó trong thư mục etc/nginx/conf.d.
Demo cho các bạn tham khảo site: nhoc.vn
Mã:
location / {
rewrite ^/([_0-9a-z-]+).html$ /index.php?prd=$1 last;
rewrite ^/danh-muc/(.*).html$ /index.php?ctg=$1 last;
rewrite ^/ho-tro/(.*).html$ /index.php?spt=$1 last;
rewrite ^/dang-nhap$ /index.php?act=login last;
rewrite ^/dang-ky$ /index.php?act=register last;
rewrite ^/gio-hang$ /index.php?act=cart last;
rewrite ^/check-out$ /index.php?act=checkout last;
rewrite ^/thanh-toan$ /index.php?act=payment last;
rewrite ^/ket-thuc$ /index.php?act=finish last;
rewrite ^/ho-tro-khach-hang$ /index.php?act=support last;
rewrite ^/member/(.*)$ /index.php?unact=user last;
rewrite ^/danh-sach-thanh-vien$ /index.php?unact=member last;
rewrite ^/hoi-dap$ /index.php?unact=faq last;
rewrite ^/don-hang$ /index.php?unact=order last;
rewrite ^/truyen-thong$ /index.php?unact=news last;
rewrite ^/tuyen-dung$ /index.php?unact=work last;
rewrite ^/back-link$ /index.php?unact=work last;
rewrite ^/life.love.shopping$ /index.php?unact=plus last;
rewrite ^/rss.map$ /index.php?menu=rss last;
rewrite ^/site.map$ /index.php?menu=map last;
rewrite ^/rss$ /xml.php?rss=home last;
rewrite ^/rss/(.*).rss$ /xml.php?rss=$1 last;
rewrite ^/sitemap.xml$ /xml.php?map last;
}
location ~ ^/sml/([0-9]+)/(.*).png$ {
try_files $uri $uri/ /image.php?id=$1&size=300;
}
location ~ ^/prd/([0-9]+)/(.*).png$ {
try_files $uri $uri/ /image.php?id=$1&size=600;
}
Sau đó restart lại VPS, Server của bạn để việc thay đổi có hiệu lực.
Lệnh restart VPS - Server nginx:
Mã:
Centos 6: service nginx restart
Centos 7: systemctl restart nginx.service
Demo nginx chạy url rewrite:
Nghe Nhạc Online
Hài Tết Mới Nhất
Chỉnh sửa cuối: