使用rewriteModule网页中删除的.aspx?(Removing .aspx from pages using rewriteModule)

   IT问题网   2019-08-13 00:00:00

问 题

我使用asp .net rewritemodule改写 http://example.com 到的 http://www.example.com 。

 <节名称="rewritemodule"type ="rewritemodule.rewritemodulesectionhandler,rewritemodule"/
 

后来才知道有这里面 system.webserver

 改写
规则
规则名称="规范"stopprocessing ="真正的"
"*"匹配url = /
条件
添加输入="{http_host}"模式="^([az] + com [。])$"/
&所述; /条件
<作用type ="重定向"url ="http:// www {c:0} / {r:0}。"redirecttype ="永久"/
 /规则
 /规则
 /重写
 

现在我想删除所有的.aspx在我的网页结束。例如:

http://www.example.com/register.aspx

将变成:

http://www.example.com/register/

我怎样才能做到这一点?

我在上godaddy的共享虚拟主机使用iis7。

解决方案

这是我开始每一个项目和标准重写规则。我只用干净的网址为所有页面(例如第一条规则适用于www.example.com/about和第二条规则www.example.com/product/123)

 改写
规则
规则名称="改写默认为aspx"stopprocessing ="真正的"
匹配url ="^ $"ignorecase ="false"/
<作用type ="重写"url ="的default.aspx"/
 /规则
规则名称="重写页面,aspx"stopprocessing ="真正的"
匹配url ="^([a-z0-9 /] +)$"ignorecase ="false"/
<作用type ="重写"url ="{r:1}的.aspx"/
 /规则
 /规则
 /重写
 

页,我需要解析出id(这种情况下,一些只),并把它添加到查询字符串我添加一个类似的规则在前面:

 规则名称="重写产品id"stopprocessing ="真正的"
匹配url ="^产品/([0-9] +)$"ignorecase ="false"/
<作用type ="重写"url ="product.aspx id = {r:1}?"/
 /规则
 

如果你想在url中使用小写和大写字母,设置ignorecase ="真正的"

修改回答你的第二个问题,加上奖金

这条规则将重定向aspx页面的干净网址:

 规则名称="重定向到url干净"stopprocessing ="真正的"
匹配url ="^([a-z0-9 /] +)aspx $"ignorecase ="真"/
<作用type ="重定向"url ="{r:1}"/
 /规则
 

替换url ="{r:1}"与url ="{tolower:{r:1}}"更改url为小写。请参阅下面你为什么会想这样做。

也是一个好主意来更新表单操作,以便回发不返回到丑陋的url。使用iis 7.5或更高版本这应该工作:

 如果(!string.isnullorempty(request.rawurl))
form1.action = request.rawurl;
 

或iis 7:

 如果(!string.isnullorempty(context.request.servervariables ["http_x_original_url"]))
form1.action = context.request.servervariables ["http_x_original_url"];
 

还有一件事要记住......这是保持所有url小写一个好主意。在url中混合下/大写字符创建的搜索引擎优化/谷歌重复内容的问题。例如website.com/about和website.com/about将加载相同的页面,但谷歌将索引它们作为两个单独的页面。

标签:使用网页删除



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

DataGrid列宽度不自动更新(DataGrid column width doesn't auto-update)

problem lt;datagridtextcolumn binding="{binding name}" wi ...

即重新present树对象(Objects that represent trees)

problem are there any objects in c# (or in .net) that rep ...

.NET:是否有可能得到的HttpWebRequest自动DECOM preSS gzip压缩的反应?(.NET: Is it possible to get HttpWebRequest to automatically decompress gzip'd responses)

problem in this answer, i described how i resorted to wra ...

如何检查是否一个程序正在使用.NET?(How to check if a program is using .NET)

problem can we check if a running application or a progra ...

使用Visual Studio安装项目以自动注册和GAC一个COM互操作DLL(Use Visual Studio Setup Project to automatically register and GAC a COM Interop DLL)

problem i've created a .net assembly for com interop and ...

如何获得MX记录与System.Net.DNS DNS名称?(How to get mx records for a dns name with System.Net.DNS)

problem is there any built in method in the .net library ...

我为什么要preFER单曲“等待Task.WhenAll”在多个等待着?(Why should I prefer single 'await Task.WhenAll' over multiple awaits)

problem in case i don't care about the order ...

我该如何分析和转换日期时间的到RFC 822的日期,时间格式?(How do I parse and convert DateTime’s to the RFC 822 date-time format)

problem how do i convert a datetime structure to its equi ...

有什么区别呢.AsNoTracking()做什么呢?(What difference does .AsNoTracking() make)

problem i have a question regarding the .asnotracking() e ...

实体框架/ LINQ到SQL:跳过和放大器;采取(Entity Framework/Linq to SQL: Skip & Take)

problem just curious as to how skip amp; take are suppose ...

StreamWriter.Flush()和StreamWriter.Close()之间的区别是什么?(What is the difference between StreamWriter.Flush() and StreamWriter.Close())

problem what is the difference in functionality between s ...

现净switch语句散列或索引?(Are .Net switch statements hashed or indexed)

problem does .net 4 (or any prior version) perform any so ...

使用LINQ生成没有选择直接更新(Use linq to generate direct update without select)

problem g'day everyone. i'm still learning l ...

是否有可能拦截控制台输出?(Is it possible to intercept Console output)

problem i call a method, say, fizzbuzz(), over which i ha ...

当使用排序列表 TKEY的,TValue在一个SortedDictionary TKEY的,TValue?(When to use a SortedList<TKey, TValue> over a SortedDictionary<TKey, TValue>)

problem this may appear to be a duplicate of this questio ...

如何初始化列表 T给定的尺寸(相对于容量)?(How to initialize a List<T> to a given size (as opposed to capacity))

problem .net offers a generic list container whose perfor ...

如何使用XPath用的XDocument?(how to use XPath with XDocument)

problem there is a similar question, but it seems that th ...

什么是WebConfigurationManager和ConfigurationManager中的区别?(What's the difference between the WebConfigurationManager and the ConfigurationManager)

problem what's the difference between the webconfiguratio ...

NUnit的测试运行秩序(NUnit Test Run Order)

problem by default nunit tests run alphabetic ...

如何恢复从C#数据库(How to restore a database from C#)

problem i have a sql 2008 db. i am running a form that ba ...