Développement web indépendant à Montpellier

Publié le mercredi 08 avril 2009 08:03:39

Réecriture d'URL asp.net et IIS

La réecriture d' n'est pas seulement possible avec apache et un fichier .htaccess. La technologie Microsoft ASP.net offre également cette fonctionnalité, qui est facile à mettre en place. Un article en fait la description détaillée sur le site MSDN de Microsoft, nous en ferons ici la synthèse pour mettre en place rapidement la réecriture d'sur un site internet dynamique.

Le fichier web.config : activer la réecriture

Tout d'abord, il faut indiquer au serveur que l'on souhaite utiliser la réecriture d'URL, lorsque l'on crée un projet Visual Studio, on a par défaut 2 entrées commentées dans le fichier Web.config :

<!--
<httpModules>
 <add type="URLRewriter.ModuleRewriter, URLRewriter" 
 name="ModuleRewriter" />
</httpModules>
-->

<!--
<httpHandlers>
 <add verb="*" path="*.aspx" 
 type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
</httpHandlers>
-->

Décommentez tout d'abord httpModules pour lancer le module de réecriture, ou httpHandlers pour utiliser le gestionnaire de réecriture. Si vous êtes plus habitués au serveur Apache qu'à IIS, ces opérations sont à peu près analogues à :

LoadModule rewrite_module modules/mod_rewrite.so

puis

RewriteEngine On

Les règles de réecritures

Les règles de réecriture sont également placées dans le fichier web.config :

<RewriterConfig>
    <Rules>
        <RewriterRule>
            <LookFor>expression recherchée</LookFor>
            <SendTo>chaine de remplacement</SendTo>
        </RewriterRule>
    </Rules>
    <!-- //...-->
</RewriterConfig>

A chaque règle de réecriture correspond un noeud RewriterRule, l'expression à rechercher dans l'URL est défini dans le sous-noeud LookFor, la page qui sera affichée sera dans le sous-noeud SendTo. Les règles sont évaluées de haut en bas, et le processus s'arrête à la première correspondance (cela correspond au flag [L] d'Apache )

A noter qu'il est possible en utilisant la classe ModuleRewriter de personnaliser les comportements de la réecriture, ce qui est particulièrement appréciable.

Exemple ancien/nouveau :

Le classique :

<RewriterRule>
    <LookFor>~/nouveau\.aspx</LookFor>
    <SendTo>~/ancien.aspx</SendTo>
</RewriterRule>

Exemple avec une URL dynamique :

L'utilisation d'expression régulière est bien entendu possible :

<RewriterRule>
    <LookFor>~/(\S*)\.aspx</LookFor>
    <SendTo>~/page.aspx?id=$1</SendTo>
</RewriterRule>

La requête http "ma_page.aspx" sera équivalente à "page.aspx?id=ma_page".

Intérêts de la réecriture d'URL

Intérêt de la réecriture d'URL pour le référencement naturel

D'après les dires, la réécriture d'URL ne serait plus d'actualité pour un bon référencement naturel.

Je ne suis pas totalement d'accord : certes les moteurs de recherches indexent très bien les pages web comprenant des variables, mais ils attribuent une importance non négligeable au texte des URLs, la réecriture permet d'éliminer tous les textes inutiles (exemple : nom de variable pas représentatif, extension...).

Intérêt de la réecriture d'URL pour l'ergonomie

De plus, il arrive que les utilisateurs avertis surfent directement en modifiant l'URL dans leur barre d'adresse, la suggestion du navigateur permet à l'utilisateur de plus facilement identifier la page qu'il souhaite trouver.

Conclusion

La réecriture d'URL n'est pas une exclusivité d'Apache, c'est parfaitement possible de l'implémenter sur un site .NET. C'est même plus simple, et plus facilement personnalisable à mon sens.

Encore aujourd'hui, il y a toujours un intérêt à réecrire ses URLs, en terme de référencement et d'ergonomie.

Notez cet article !

  • Actuellement 5 sur 5 étoiles
  • 1
  • 2
  • 3
  • 4
  • 5

Note : 5/5 (1 notes attribuées)

Merci d'avoir participé !

Vous avez déjà noté cette page, vous ne pouvez la noter qu'une fois !

Votre note a été changée, merci de votre participation !

Bonne résolution ! j'arrête d'alourdir mes pages avec des boutons de partage, mais vous pouvez continuer de partager :-)

Commentaires

  1. When we hit the bottom, then it goes up.

  2. She couldn't be at home in the night time because, It made her feel alone but at that time she was too young

  3. I appreciate your sharing, the information is great and rewarding.

  4. Things are very open and intensely clear explanation of issues was truly informative.

  5. mankirt a... | mankirt aulakh’s badnam song |

    This is an awesome blog. You provide very useful data.
    https:/...a-big-hit/ mankirt aulakh’s badnam song

  6. Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place.
    http://...marketing/

  7. hipster-v... | hipster-vintage-and-indie |

    Howdy, May I grab that photo and usage it on my website?

  8. Aw, i thought this was quite a nice post. In concept I must set up writing like this additionally – spending time and actual effort to make a great article… but exactly what do I say… I procrastinate alot through no means appear to go carried out.
    http://...onster.com

  9. It was a very good post indeed. I thoroughly enjoyed reading it in my lunch time. Will surely come and visit this blog more often. Thanks for sharing.
    http://...-designer/

  10. Hi, I find reading this article a joy. It is extremely helpful and interesting and very much looking forward to reading more of your work.
    http://...echnology/

  11. Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place.
    http://...lifestyle/

  12. Thanks for the blog article.Really looking forward to read more. Really Great. https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today https:/...ults.today

  13. Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place.



    http://...thbase.com

  14. Hi, I have scanned the greater part of your posts. This post is presumably where I got the most valuable data for my exploration. A debt of gratitude is in order for posting, possibly we can see more on this. Are you mindful of some other sites on this subject.
    http://...dvisor.com

  15. Computer... | Computer Network online |

    Dissertation Guidance Provides Quality Online Dissertation Help For Students.

  16. Take My P... | Take My Programming Homework |

    John Arnold Is An Academic Writer Of The Dissertation-Guidance. Who Writes Quality Academic Papers For Students To Help Them In Accomplishing Their Goals.

  17. Hello Guys, I was searching for some <a href=https:/...>rubber products</a>, which were truly valuable and they are doing this work with being well disposed with pockets.

  18. led penda... | led pendant light manufacturer |

    led pendant light manufacturer is some really fascinating led pendant light manufacturer you all would love to around in your house.

  19. I truly value this awesome post that you have accommodated us. I guarantee this would be gainful for the greater part of the general population.
    http://...oftseo.com

  20. This survey is all worrying the customer's satisfaction. This survey is begun to acknowledge worrying their customer's endorsements to maintain their remedy in addition to food.

  21. Do My Psy... | Do My Psychology Homework For Me |

    I Loved The Way You Discuss The Topic Great Work Thanks For The Share.
    https:/...nments.com

  22. Programmi... | Programming Homework Help Online |

    This Is Really Great Work. Thank You For Sharing Such A Good And Useful Information Here In The Blog For Students.
    https:/...ingdoc.com

  23. http://ww... | http://www.poker18dewa.com |

    Hi there just wanted to give you a quick heads up. The words in your article seem to be running off the screen in Internet explorer. I’m not sure if this is a format issue or something to do with internet browser compatibility but I figured I’d post to let you know. The design and style look great though! Hope you get the issue solved soon. Thanks

  24. Programmi... | Programming Project Help |

    I Appreciate This Work Amazing Post For Us I Like It.
    The Leading Assignment Help UK Firm Offers State Of The Art Services To Its Clients With A Promise Of Delivering All The Required Work Well Within The Deadline.
    This Is Really Great Work. Thank You For Sharing Such A Good And Useful Information Here In The Blog For Students.
    I Am So Happy To Read This. This Is The Kind Of Manual That Needs To Be Given And Not The Random Misinformation That's At The Other Blogs.

  25. lesa.prom... | chemistry assignment help |

    Thank you for the wonderful blog. Our chemistry assignment help expert is happy to see this post.

  26. economics... | Economics Homework Help Online |

    The Leading Assignment Help UK Firm Offers State Of The Art Services To Its Clients With A Promise Of Delivering All The Required Work Well Within The Deadline.

  27. Good Way Of Telling, Good Post To Take Facts Regarding My Presentation Subject Matter, Which I Am Going To Deliver In My College

  28. This is a great article, that I really enjoyed reading. Thanks for sharing. https:/...result.org https:/...uotes.com/

  29. Webroot.com/safe- Experience next-generation Security level with Webroot on your all devices. Install and activate webroot from www.webroot.com/safe and don’t forget to run webroot safe scan to feel secure anywhere.webroot.com/safe is a computer security software program for Microsoft Windows users that combine software as a service cloud protection with traditional Antivirus and anti-spyware desktop technologies. Built into the suite is a two-way firewall, a registry cleaner, Email anti-spam, secure browsing, anti-phishing and a password management service. The suite was initially released on July 26, 2010, as the 2011 version of the product.

    http://...t.com/safe

  30. Auto Glas... | Auto Glass Replacement |

    I ran into this page on accident, surprisingly, this is a great website. The site owner has carried out a superb job of putting it together, the info here is really insightful. You just secured yourself a guarenteed reader.

  31. After I initially commented I clicked the -Notify me when new feedback are added- checkbox and now every time a remark is added I get four emails with the same comment. Is there any manner you may remove me from that service? Thanks!

  32. Webroot Support experts can lend their hand to download, install and update Webroot Spy Sweeper Antivirus on your system. We can also repair all errors that may crop up while installing and configuring Webroot Antivirus on your PC. We can help you detect and remove malicious threats, malware and spyware by performing a quick scan on all files and folders. With our robust technology, we can destroy suspicious programs and infected files from your system. Our antivirus experts can clean all online threats, including Trojan, root kits, key loggers, and worms in just single sweep. We can optimize your computer’s speed and efficiency and also protect it from being sluggish.
    http://...t.org/safe

  33. Install a... | Install and Activate Webroot safe @ www.webroot.com/safe |

    www.webroot.com/safe is a computer security software program for Microsoft Windows users that combine software as a service cloud protection with traditional Antivirus and anti-spyware desktop technologies. Built into the suite is a two-way firewall, a registry cleaner, Email anti-spam, secure browsing, anti-phishing and a password management service .

    http://...omsafe.us/

  34. With the development of the digital world, online protection is crucial. It is extremely important to protect your PCs, Mac, computers as well as mobile devices and tablets with webroot.com/safe. This can be done with the help of effective internet security and anti-virus products from www.webroot.com/safe that safeguards all devices used on digital platforms. Webroot is a private American company that provides comprehensive internet security solutions for consumers as well as businesses with various products. These services are available for home based computers, small offices as well as large business enterprises by preventing potential dangers in real time whenever they connect in the digital space for both personal and professional purposes.



    http://...broot.com/

  35. Despite firewalls, antivirus software, security services, and identity protection, there are still many cybersecurity vulnerabilities that you should keep in mind. Follow these 10 best practices, or basic rules, in order to help maintain your security on the web.

    http://...oncom.com/


  36. http://...opers.com/ Web Development Company
    http://...velopment/ Shopify Development Services
    http://...velopment/ Volusion Customization Services
    http://...velopment/ Magento Development Services
    http://...velopment/ BigCommerce Development Services
    http://...velopment/ WordPress Development Services
    http://...developers
    http://...n-services
    http://...y-services
    http://...tee-shirts
    http://...om-shirts/
    http://...dfresh.com

  37. sf@gmail.com | voyance par telephone gratuit |

    Not a solitary 2nd abandoned abandoning me in absolute surprise.

  38. www.webro... | www.webroot.com/safe | webroot/safe - download (windows 10) |

    Webroot Support provides all-round assistance for Webroot Antivirus. As soon as you register yourself for the use of Internet facility and get the advantage of surfing the World Wide Web, you are open to innumerable threats transmitted to your system due to online browsing sessions. Encounter perfect malware blocking with Webroot Antivirus. Let Webroot Support with its techsmarties help you protect your system and rectify the security issues. We at Webroot Support , have team of experts who help you or guide through all the stages of Webroot installation process.
    http://....org/safe/

  39. Webroot Support experts can lend their hand to download, install and update Webroot Spy Sweeper Antivirus on your system. We can also repair all errors that may crop up while installing and configuring Webroot Antivirus on your PC. We can help you detect and remove malicious threats, malware and spyware by performing a quick scan on all files and folders. With our robust technology, we can destroy suspicious programs and infected files from your system. Our antivirus experts can clean all online threats, including Trojan, root kits, key loggers, and worms in just single sweep. We can optimize your computer’s speed and efficiency and also protect it from being sluggish.
    http://...b-root.org

  40. webroot.c... | webroot.com/safe to get webroot safe setup |

    Experience next generation Security level with Webroot in your all devices. Install and activate webroot from www.webroot.com/safe and don’t forget to run webroot safe scan to feel secure anywhere.webroot.com/safe is a computer security software program for Microsoft Windows users that combine software as a service cloud protection with traditional Antivirus and anti-spyware desktop technologies. Built into the suite is a two-way firewall, a registry cleaner, Email anti-spam, secure browsing, anti-phishing and a password management service .The suite was initially released on July 26, 2010 as the 2011 version of the product.
    http://...-com-safe/

  41. welcome to avg.com/retail website With the development of the digital world, online protection is crucial. It is extremely important to protect your PCs, Mac, computers as well as mobile devices and tablets with avg.com/retail. This can be done with the help of effective internet security and anti-virus products from avg.com/retail that safeguards all devices used on digital platforms.

  42. Visit www.norton.com/setup for setup, download, reinstall, enter and activate your norton product key to setup your account.Step-by-Step guide for Norton setup key, Download &amp; installation from norton.com/setup website.

  43. I knew it might be a masterpiece the instant I started reading the weblog.

  44. Among one in all the best items on the online, refreshing in its specificity.

  45. The writings so beautifully composed. They are just irresistible.

  46. Ooooooo a cherché longtemps, merci.

  47. Dissertat... | Dissertation Writers Service United Kingdom |

    Good way of telling, good post to take facts regarding my presentation subject matter, which i am going to deliver in my college

  48. Ceaselessly steady and an exceptional sense of duty regarding the universe of bloggers.

  49. Psycholog... | Psychology Assignment Help Assistance |

    This site and the resources you provide is really nice keep it up.

  50. Harvard C... | Harvard Case Study Analysis |

    I am so happy to read this. This is the kind of manual that needs to be given and not the random misinformation that's at the other blogs.

  51. The blog is clear demonstration of the fact that, you can’t compromise with the quality.

  52. Good way of telling, good post to take facts regarding my presentation subject matter, which i am going to deliver in my college

  53. If you wish to download and install apk files for your phones as well as tablets Windows Phone and also other brand names such as Oppo.

  54. dg@gmail.com | brian holm lawyer san diego |

    The blog delineates how hard the essayist has taken a shot at this.

  55. I regularly visit your site and find a lot of interesting information.
    Not only good posts but also great comments.
    Thank you and look forward to your page growing stronger.

  56. i dont think that i can make it like this anyway in my lifetime :( it is saddening but i will do try all my best. thank you for teaching.

  57. Réecriture d'URL asp.net et IIS

  58. Respecting the time and exertion you put into your site and nitty gritty data you offer.

  59. It's great because of the knowledge you share with us, I will always follow your blog and will share your blog with my friends

  60. Mountain... | Mountain Man Brewing Company Case Break Even Analysis |

    I personally like your post, you have shared good article. It will help me in great deal.

  61. Statistic... | Statistics Homework Solution |

    Hi buddy, your blog' s design is simple and clean and i like it. Your blog posts about Online writing Help are superb. Please keep them coming. Greets!

  62. hhhh@gmai... | http://www.healthncure.net/recommendations-for-protecting-your-skin-from-the-suns-rays/ |

    This blog is so valuable. A present for the blog perusers.

  63. Eloquently composed and well thoroughly considered.

  64. Mind boggling post. I found your site perfect for my necessities. To a great degree important information especially the last part. Thankful to you for giving to us, and we genuinely believe you will continue refreshing or post distinctive articles

  65. My personal view is that I have a dynamic page that shows an alternate item as per the factors go in the url, for url reworking impecc, however for redirection I don't have a clue.

  66. I was surfing net and fortunately came across this site and found very interesting stuff here. Its really fun to read. I enjoyed a lot. Thanks for sharing this wonderful information.

  67. I found your this post while searching for information about blog-related research ... It's a good post .. keep posting and updating information.

  68. marketing... | marketingassignmentz.com |

    Things are very open and intensely clear explanation of issues. was truly information. Your website is very beneficial.

  69. I’m really impressed with your article, such great & usefull knowledge you mentioned here.

  70. start free streaming on windows OS using Mobdro application. Download Mobdro for PC 2017, windows 10, 8.1, 8, 7 laptop computer. Mobdro Apk download Android is new way to enjoy the streaming from android with any brands of mobile phone.

  71. Download aptoide for ios and get all the playstore apps for free, you can check how to use aptoide apple and aptoide ios for iPhone users.Download Aptoide apk 2.2 and all version history for Android. Download Aptoide app for Android.

  72. This is truly a decent and educational, containing all data furthermore greatly affects the new innovation. A debt of gratitude is in order for sharing it

  73. How To Ki... | How To Kiss A Man Review |

    hi!! Extremely intriguing exchange happy that I ran over such useful post. Keep doing awesome. Happy to be a piece of your net group.

  74. This is my first time i visit here. I discovered such a large number of fascinating stuff in your web journal particularly its examination. From the huge amounts of remarks on your articles, I figure I am not by any means the only one having all the happiness here! keep doing awesome

  75. This is my first time visit here. From the tons of comments on your articles,I guess I am not only one having all the enjoyment right here!

  76. good, I've been looking for

  77. Mon pb est que j'ai une page dynamique qui affiche un produit différent suivant les variables passées dans l'url, pour l'url rewriting impecc, mais pour la redirection je ne sais trop comment faire

  78. www.comca... | www.comcast customer service |

    I really like the dear information you offer in your articles. I’m able to bookmark your site and show the kids check out up here generally.

  79. these are a few of the adjectives that best anxiety Ray Ban eyeglasses. Aloft finishing his analysis he at http://...opuk.co.uk provides relevant, un-biased admonition to his readers depending on his discoveries and abandoned experiences.

  80. Je vous remercie infiniment pour toutes ces informations

  81. La réécriture d'URL est vraiment un point de plus pour avoir des URLs propres facile à appréhender que ce soit par l'internaute que par les moteurs de recherche.

  82. Arthur | Après les redirections, la réécriture pour l'asp |

    Merci pour ces infos.

    J'avais trouvé une "astuce" (à contre cœur) pour ce qui était des redirections en utilisant un fichier.asp et le JavaScript. Mais pour la réécriture, j'étais perdu au début.

    Je vais tester ça, perso les pages sont en ".asp" et non ".aspx" sur un serveur 2iS, mais je pense que ça devrait passer !

  83. Impeccable merci pour cet article, par contre j'avais une question, une fois toute la réecriture ok, comment indiqué une redirection 301 de ces pages réecrites dans le web.config ?
    Mon pb est que j'ai une page dynamique qui affiche un produit différent suivant les variables passées dans l'url, pour l'url rewriting impecc, mais pour la redirection je ne sais trop comment faire..;
    j'ai vu qu'on pouvait mettre dans l'ente de la page une conditions et la redirection 301 mais vu le nb de cas de produits pour cette page je vais avoir un header de 5000 lignes !!

    qqun a une idée ?

    merci d'avance.

    newverbal@yahoo.fr

  84. Stéphane... | Re : incohérence ou incompréhension |

    Bonjour,

    C'est exactement ce que j'ai voulu dire, merci d'avoir prêté attention !

  85. Rey | incohérence ou incompréhension |

    Bonjour,
    Je relève une incohérence au niveau de la configuration du Rewriter et l'exemple que vous donnez :
    votre exemple :
    <RewriterRule>
    <LookFor>~/(\S*)\.aspx</LookFor>
    <SendTo>~/page.aspx?id=$1</SendTo>
    </RewriterRule>
    Cela redirigera "page.aspx?id=ma_page" vers "ma_page.aspx".

    le fonctionnement :
    l'expression à rechercher dans l'URL est défini dans le sous-noeud LookFor, la page qui sera affichée sera dans le sous-noeud SendTo.

    Ce qui est le contraire de l'exemple. Ou alors, vous n'utilisez pas les bons termes. Peut-être avez-vous voulu dire <<Cela affichera "ma_page.aspx" au lieu de "page.aspx?id=ma_page">> ?