URL Rewriting dùng ASP/IIS

by degiocuondi.com 1. December 2009 10:53

URL Rewrite giúp địa chỉ trang web dễ nhìn hơn, đặc biệt là giúp SEO (Search Engine Optimation) tốt hơn. Hôm nay tôi xin hướng dẫn bạn làm URL Rewrite trên ASP/IIS.

Tôi có : http://degiocuondi.com/news.asp?id=1
nhưng tôi muốn bạn nhìn thấy dạng : http://degiocuondi.com/news/1

Sự khác nhau là “/news/1” dể coi hơn “/news.asp?id=1”.

Chúng ta cùng bắt đầu:

 

Bước 1: Tạo file asp-rewrite.asp trên website http://degiocuondi.com/ với code:


1.  Class URL

2.   

3.   Private aURL ' Mảng các phần tử trong URL

4.   

5.   Private Sub Class_Initialize()

6.    sTemp = Request.Querystring

7.    ' Bỏ các ký tự dầu trong URL: “404;”, “403”

8.    sTemp = Right(sTemp, len(sTemp) - 4)

9.    ' Bỏ đi phần địa chỉ chính trong URL

10.  sTemp = replace(sTemp, "http:// degiocuondi.com:80/", "")

11.  sTemp = replace(sTemp, "http:// degiocuondi.com /", "")

12.  ' Thêm ký tự “/” sau cùng nếu chưa có

13.  If Right(sTemp, 1) <> "/" then

14.   sTemp = sTemp & "/"

15.  End If

16.  aURL = split(sTemp, "/")

17. End Sub

18. 

19. Public Property Get url(index)

20.  If index > uBound(aUrl) then

21.   url = ""

22.  Else

23.   url = trim(aUrl(index))

24.  End If

25. End Property

26. 

27.End Class

28. 

29.Set MyUrl = New URL

30.Session(0) = MyUrl.url(1))

31.Server.Transfer("/" & MyUrl.url(0) & ".asp”)

Bạn để ý, mấu chốt nằm ở lệnh:

 

server.transfer

Lệnh này chuyển xử lý đến 1 file nào đó (news.asp chẳng hạn)

 

Ý nghĩa của trang asp-rewrite.asp là khi người dùng truy cập địa chỉ

 http://degiocuondi.com/news/1

sẽ nhận được kết quả

 

 

File asp-rewrite.asp có nhiệm vụ transfer xử lý về

http://degiocuondi.com/news.asp?id=1

 
Bước 2: Tạo file news.asp trên website http://degiocuondi.com/ với code:


1.  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

2.  <%

3.  id = Session(0)

4.  Response.Write "Nội dung tin số " & id

5.  %> 

Bước 3: Cấu hình để chuyển lỗi 404, 403, 405 về file asp-rewrite.asp xử lý. Lỗi 500 chuyển xử lý về global.asa

 

  • 403;14 (Forbidden - Directory Listing Denied) ==> asp-rewrite.asp
  • 404 (Not Found) ==> asp-rewrite.asp
  • 405 (Method Not Allowed) ==> asp-rewrite.asp
  • 500;15 (Internal Server Error) ==> global.asa (để hiện thị lỗi)

Hoàn tất! Bây giờ bạn có thể vào http://degiocuondi.com/news.asp?id=1001 mà cũng có thể vào http://degiocuondi.com/news/1001

Cảm ơn sự trợ giúp của Rust Indy/ASP Free.Com !


Tags: , , , , ,

Kinh nghiệm máy chủ

Comments (4) -

10/12/2011 7:53:31 PM #

riad Marrakech

Merely miss to voice your composition is as wonderful. The brightness in your broadcast is merely stunning also i can think you’re a adept on this topic. Well unison along your leave tolerate me to clinch your grub to halt updated along near courier. Bless you undivided million also gratify cart on the gratifying process.

riad Marrakech France | Reply

11/7/2011 9:33:37 AM #

Voyage Marrakech

Nevertheless a smiling visitant here to moiety the enthusiasm (:, btw prominent method . “Forget rue, or soul is yours to skip.” by Jonathan Larson.

Voyage Marrakech France | Reply

11/13/2011 8:58:37 AM #

Marrakech ici

Hey There. I discovered your weblog using msn. This is a indeed well written report. I testament earn indisputable to bookmark it besides happen abaft to predict over of your helpful report. Bless you for the courier. I testament definitely repartee.

Marrakech ici France | Reply

11/16/2011 2:19:31 AM #

immobilier maroc tanger

Thanks for sum your tasks that you experience put in this. mere interesting info . “Either you flee the time or the time flees you.” by Jim Rohn.

immobilier maroc tanger France | Reply

Add comment

  Country flag

biuquotecode
  • Comment
  • Preview
Loading

Tài trợ bởi Lạc Tâm. Hosting bởi ProHOST
Powered by BlogEngine.NET 2.5.0.6 - Old School Theme by n3o Web Designers

Menu

Bookmark and Share Log in
 

Ads Word

SEO TOP GOOGLEGiải pháp SEO hiệu quả nhất. Vui lòng liên hệ 0936 122773http://www.lactam.vn/

Tài trợ

Google Pagerank icon
Search Engine Optimization and SEO Tools
Submit Sitemap