Rewrite URL

rewrite url là một kỹ thuật cho phép ghi lại địa chỉ website (URL) từ dạng này thành một dạng khác (URL rewriting). Rewrite URLs (đôi khi gọi là short Urls, URL rewriting, hay fancy URLs) sử dụng để tạo ra một địa chỉ Web ngắn hơn và dễ nhìn hơn đối với trang Web. Kỹ thuật này được biết đến như một trong những thủ thuật nhằm tối ưu hóa địa chỉ cho các cỗ máy tìm kiếm (SEO URL)

Ví dụ

URL sau có chứa chuỗi truy vấn liên quan đến Module, hàm và thứ tự bài viết:

http://www.example.com/Blogs/modules.php?name=News&op=viewst&sid=696

Nó có thể được viết như sau để người xem dễ hiểu hơn:

 http://www.example.com/Blogs/News/viewst/696.html

Địa chỉ thứ 2 có thể cho phép người truy cập thay đổi giữa các cấp thư mục để xem các bài viết ở cấp cao hơn. Ví dụ URL sau cho phép người truy cập xem tất cả các bài viết

http://www.example.com/Blogs/News/

Một cách viết khác cho trường hợp

http://example.com/wiki/index.php?title=Page_title

thành

http://example.com/Page_title

Tác dụng của Rewrite URL:[1]

  • Làm URL của trang web trở nên thân thiện và giúp tối ưu hóa công cụ tìm kiếm
  • Ngăn chặn "liên kết nội tuyến" không mong muốn
  • Không để lộ (thông qua URL) hoạt động bên trong của một trang web trước người truy cập.
  • Các URL của các trang trên các trang web có thể được giữ ổn định ngay cả khi công nghệ nền tảng được sử dụng để phục vụ chúng thay đổi

Những nhược điểm:

  • Trong một số trường hợp, viết Rewrite không khoa học có thể gây ra lỗi khi người sử dụng sửa đổi một URL để truy cập ở cấp cao hơn của Website. Xem ví dụ dưới đây:
Nếu sửa link
http://www.example.com/Blogs/News/viewst/696.html
thành
http://www.example.com/Blogs/News/viewst/
sẽ gây lỗi.
  • Việc tạo ra link ảo và thêm các thành phần phục vụ mục đích SEO có thể gây ra những rắc rối không lường trước [2].
  • Kỹ thuật này phải được áp dụng liên tục và lâu dài trên một website và chỉ nên thực hiện trên 1 site mới. Việc thay đổi có thể khiến Website rớt hạng thê thảm trên các công cụ tìm kiếm (tác dụng ngược của SEO).

Nền tảng Web

Nhiều nền tảng web có hỗ trợ URL rewriting, bao gồm hỗ trợ trực tiếp hoặc sử dụng các module mở rộng.

  • Apache HTTP Server có hỗ trợ URL rewriting bằng mod_rewrite module
  • URL Rewrite có thể sử dụng như thành phần mở rộng cho Microsoft IIS[3]
  • Ruby on Rails có sẵn URL rewriting qua Routes[4]
  • Java Server Faces có URL rewriting thông qua PrettyFaces: URL rewriting extension for JSF
  • Django sử dụng nền tảng hệ thống regular-expressions[5]
  • Java Stripes Framework đã có chức năng này, được tích hợp từ phiên bản 1.5[6]
  • Có nhiều nền tảng sử dụng Perl đã có tính năng này [cần dẫn nguồn]

From a software development perspective, URL rewriting can aid in code modularization and control flow [7], making it a useful feature of modern web frameworks.

Xem thêm

  • Permalink
  • Apache HTTP Server
  • Internet Information Server
  • Zeus Web Server
  • Content negotiation
  • HTTP
  • .htaccess

Chú thích

  1. ^ Many of these only apply to HTTP servers whose default behavior is to map URLs to filesystem entities (i.e. files and directories); certain environments, such as many HTTP application server platforms, make this irrelevant.
  2. ^ Thông báo về URL giả mạo bài viết trên Dân trí
  3. ^ Microsoft Web Platform
  4. ^ “Routes”. Bản gốc lưu trữ ngày 9 tháng 5 năm 2008. Truy cập ngày 22 tháng 10 năm 2009.
  5. ^ Django URLconf
  6. ^ clean urls in Stripes 1.5
  7. ^ “DocForge: Clean URL”. Bản gốc lưu trữ ngày 20 tháng 10 năm 2009. Truy cập ngày 22 tháng 10 năm 2009.

Liên kết ngoài

Apache

  • mod_rewrite Apache module described as "the Swiss Army knife of URL manipulation".
  • Apache Rewrite Guide This document supplements the mod_rewrite reference documentation. It describes how one can use Apache's mod_rewrite to solve typical URL-based problems with which webmasters are commonly confronted.
  • mod_alias Simpler Apache module allow for manipulation and control of URLs as requests arrive at the server.

IIS (Microsoft Internet Information Services)

  • How to redirect URLs to different Web sites Microsoft Knowledgebase article on built-in URL rewriting
  • Scott Guthrie of Microsoft describes various techniques for URL rewriting in.NET
  • URL Rewrite Module for IIS 7.0 from Microsoft
  • URL Rewriter and Reverse Proxy Lưu trữ 2017-12-23 tại Wayback Machine for use on IIS 6.0 and 7.0 from Managed Fusion

Zeus Web Server

  • Converting Apache rules to ZWS Lưu trữ 2008-08-28 tại Wayback Machine
  • Redirecting clients to Alternate Pages Lưu trữ 2009-10-10 tại Wayback Machine
  • Zeus Web Server User Guide Lưu trữ 2009-03-06 tại Wayback Machine see page 140 "Configuring Request Rewrite Scripts" (PDF 3.58MB)

Note: Unlike Apache, entering rewrite rules in an .htaccess file will not work. They must be entered in Zeus' proprietary Request Rewrite scripting language through the zeus server's admin panel, which creates a rewrite.script file and installs it into the server. Unless you have access to the main server administration interface, you will need to ask your hosting provider to implement your rule.

Java Platform, Enterprise Edition (Java EE) Servlet container servers (Apache Tomcat, Resin, Orion etc)

  • HttpRedirectFilter (open source)
  • UrlRewriteFilter (open source - BSD) - allows you to rewrite URLs before they get to your code. Supports XML or mod_rewrite style config.