我有一个 .ashx 文件,为我们的 rss feed 和站点地图生成 xml。我们的新 SEO 人员告诉我们“.ashx”扩展名正在伤害我们(例如,坚持现有的“sitemap.ashx”文件应命名为“sitemap.xml”,而 rss 提要为“site.rss” )。
我工作的组织几乎把我与托管和开发混为一谈,而托管并不是我有很多经验的事情(我勉强过得去,但不是专家)。
我知道这可能是 IIS 中的某种情况,这样对一件事的请求会得到另一件事的服务,但是有人可以快速推动我走向正确的方向吗?我现在连想出一些东西来谷歌都遇到困难!
编辑:在本例中是 IIS7 和 ASP.net 3.5
I have a .ashx file generating xml for both our rss feed and our sitemap. Our new SEO guy is telling us that the ".ashx" extension is harming us (for example, insisting that the existing "sitemap.ashx" file should be called "sitemap.xml", and the rss feed is "site.rss").
The organization I work for has pretty much lumped me with the hosting as well as the developing, and hosting isn't something I have a lot of experience of (I get by, but not an expert).
I know this is likely to be something in IIS such that requests for one thing get served another thing, but can someone give me a quick nudge in the right direction? I am having trouble even coming up with something to google right now!
EDIT: In this instance it's IIS7 and ASP.net 3.5
发布评论
评论(5)
听起来您想要公开/服务
http://foo.com/site.rss
,但实际上执行http://foo.com/bar.ashx
>。对于 IIS7 ,实现 URL 重写模块与“重写映射规则”。
在你的 web.config 中尝试一下:
It sounds like you'd want to expose/serve
http://foo.com/site.rss
, but actually executehttp://foo.com/bar.ashx
.For IIS7 , implement the URL Rewriting module with "Rule with rewrite map".
Try this in your web.config:
无需重写,您可以配置 .ashx 以响应 web.config 中的 .rss 或 .xml。您始终可以添加查询字符串参数来响应不同的逻辑。
...等
no rewrite needed, you can have can configure the .ashx to respond to .rss or .xml in the web.config. you can always add query string parameters to respond to different logic.
...ect
您正在寻找的内容称为“URL 重写”,而 IIS 并没有提供完全的盒子里,有很多方法可以实现它。
有了 Apache,你就有了 mod_rewrite。对于 IIS(从版本 7 开始),我认为您已经拥有模块。看一下:IIS URL 重写模块 2
如果您正在寻找更多信息或计划自行部署,请查看此处:ASP.NET 中的 URL 重写。
如果您在共享托管服务器上托管网站,您可能无法在 IIS 中安装自定义模块,但您可以将其部署为应用程序的一部分。
What you are looking for is called "URL Rewriting" and while IIS doesn't provide quite out of the box, there are ways you can achieve it.
With Apache, you had mod_rewrite. With IIS (starting with version 7) which I presume you have you have Modules. Take a look at: IIS URL Rewrite Module 2
And if you're looking for more information or you're planning to roll-your-own, have a look here: URL Rewriting in ASP.NET.
If your hosting the website on a shared hosting server you may not be able to install a custom module in IIS but you may be able to deploy it as part of your application.
IIS URL Rewrite 2.0?
顺便说一句,它通常是安装的在诸如 godaddy.com 或discountasp.net 等共享主机上进行设置,因此您只需要编写配置即可。
IIS URL Rewrite 2.0?
BTW, it's usually installed & set up on shared hostings such as godaddy.com or discountasp.net, so you'll only need to write the config.
如果您足够幸运能够使用 ASP.NET MVC,则可以相对轻松地通过 global.asax 中的路由表添加重定向。
根据记忆,您添加如下路由:
这将捕获对 Specificname.xml 的任何请求,它们将转到名为 home 的控制器,并执行重新路由操作,您可以将其重定向到处理程序或将处理程序代码移动到其中。
-编辑-
也就是说,我可能会选择 p.campbell 提供的静态路由选项。
If you're lucky enough to be using ASP.NET MVC you can relatively easily add redirection through the routes table in the global.asax.
From memory, you add a route like so:
This would capture any requests for specificname.xml and they'd go to a controller called home, with an action of reroute which you could just redirect to your handler or move your handler code to.
-Edit-
That said, I'd probably go for the static routing option offered by p.campbell.