Hướng dẫn Rewrite URL trong asp.net

Hướng dẫn Rewrite URL trong asp.net

Một trong những bước quan trọng khi tiến hành tối ưu hoá website là sử dụng URL thân thiện với google. Trong bài viết này WEBXAULA sẽ giới thiệu với các bạn cách viết lại URL trong asp.net 

Hướng dẫn Rewrite URL trong asp.net

Thông thường, URL website của bạn sẽ có dạng http://your-domain/Default.aspx?p=1.

Nhưng những url dạng này google sẽ rất khó index trang của bạn. Bạn nên  viết lại URL của bạn thành dạng như http://your-domain/san-pham/san-pham-1 sẽ rất thân thiện với google.

Đầu tiên bạn cần download thư viện UrlRewritingNet tại đây.

Bạn khai báo trong web.config

<configSections>

<sectionname="urlrewritingnet"

type="UrlRewritingNet.Configuration.UrlRewriteSection,UrlRewritingNet.UrlRewriter"

requirePermission="false"

restartOnExternalChanges="true"/>

</configSections>

<urlrewritingnet rewriteOnlyVirtualUrls="true"

contextItemsPrefix="QueryString"

defaultPage="default.aspx"

defaultProvider="RegEx"

xmlns="http://www.urlrewriting.net/schemas/config/2006/07">

<rewrites>

 <addname="RedirectInApplication"

virtualUrl="^~/redirect/(.*)/Default.aspx"

rewriteUrlParameter="ExcludeFromClientQueryString"

destinationUrl="~/$1/Redirected.aspx"redirect="Application" 

redirectMode="Permanent"ignoreCase="true"/>

   <addname="1"virtualUrl="^~/san-pham/(.*)-(.*).html"

rewriteUrlParameter="ExcludeFromClientQueryString"

destinationUrl="~/page/Default.aspx?pID=$2"

ignoreCase="true"/>

                    
  <addname="KickBrowserToDomain"

virtualUrl="^http\://(.*)/kickto/(.*).aspx"

rewriteUrlParameter="ExcludeFromClientQueryString"

destinationUrl="http://$2?source=$1"

redirect="Domain"

redirectMode="Permanent"

ignoreCase="true"/>

   </rewrites>

</urlrewritingnet>
<httpModules>

   <addname="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule,

   UrlRewritingNet.UrlRewriter"/>

</httpModules>


<modules>


Lưu ý bạn nào dùng IIS7 trở lên cần khai báo thêm trong phần  <system.webServer>

       
<removename="ScriptModule" />

<addname="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule,

UrlRewritingNet.UrlRewriter" />

</modules>
 

Trong phần in đậm trong code là phần để các bạn add thêm các phần viết lại URL cho website của bạn.

Bạn thấy bài viết này như thế nào?: 
Average: 10 (1 vote)
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Showing a Twitter Feed in a Drupal Block

Hiển thị Twitter Feed với một Drupal Block

In this tutorial we'll show you how to place a Twitter feed inside a block. You can then display that Twitter feed anywhere around your theme. There are many different Twitter options out there but most have a couple of limitations:

Khuyên bạn nên sử dụng 15 Outstanding Drupal Modules

Khuyên bạn nên sử dụng 15 Outstanding Drupal Modules

Drupal is a (CMS) any web developer should get to know. It is in my opinion the best open source CMS available at the moment, and it has a huge community of contributors

[Joomla, Wordpress, Drupal] Multisites là 1 ý kiến tồi cho Many Sites

[Joomla, Wordpress, Drupal] Multisites là 1 ý kiến tồi cho Many Sites

As open source becomes more and more popular, we see organizations rolling out many sites across their organization. As they try to manage them, many of them turn to "multis

Công ty diệt chuột T&C

 

Diet con trung