使用Querystring重写/重定向URL? [英] URL Rewriting/Redirects with Querystring?

查看:306
本文介绍了使用Querystring重写/重定向URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一种情况,我有一堆带有查询参数的网址,用于基本上重定向到各种网站,有点像短网址或索引。

We have a situation where I have a bunch of urls with query params that are used to bascially redirect to various sites, kind of like a short URL or index.

例如:www.mysite.com/abc?x=123重定向到www.google.com
www.mysite.com/abc?x=456,重定向到www.yahoo.com
和所以...

Ex: www.mysite.com/abc?x=123 which redirects to www.google.com www.mysite.com/abc?x=456 which redirects to www.yahoo.com and so on...

问题是现在或之前没有实际的页面abc,这些链接是在网站上创建和发布的。问题是现在找到一种简单的方法使它们处于活动状态,因此当点击它时会进行正确的重定向。

The issue is that there isn't an actual page "abc" now or prior, these links were created and published unknown to the site. The issue is now finding a simple means to make them active so when clicked will do the proper redirects.

这是当前在IIS Windows服务器上。核心站点本身是基于.NET的。

This is currently on an IIS Windows server. The core site itself is .NET based.

有没有办法使用htaccess文件或类似文件(假设我们使用IIS的mod-rewrite isapi插件)来允许创建这些重定向?我们有数百个要创建。

Is there a way using an htaccess file or similar (assuming we use a mod-rewrite isapi plugin for IIS) to allow creating these redirects? We have hundreds of these to create.

我能想到的另一个选择是将这些选项重定向到一个实际的asp.net页面,然后该页面将处理param并重定向代码中的逻辑,假设我们可以轻松地从基本URL到实际页面进行重定向。

The only other option I can think is redirecting these in turn to an actual asp.net page which would then process the param and redirect logic in code, assumign we can do a rredirect from the base URL to a real page easily.

我猜的真正问题是用abc?x =来解决问题456当没有实际页面时,无论如何都没有给页面放置。

The real problem I guess is getting around delaing with "abc?x=456" when there is no actual page in existence and no extension is given anyway to put a page in place.

推荐答案

如果 abc 不存在,您的服务器将以404响应。在ASP.NET中,您可以选择如何响应它 - 它在web.config中作为CustomErrors 。打开它,然后重定向到一个花哨的404页面(也许你已经这样做了)。然后,花哨的404页面可以检查请求的查询字符串(它被作为另一个查询字符串传递到自定义错误页面)以查看它是否是有效的重定向,存在于您的数据库中等。只需执行Response.Redirect(从那里。

If abc doesn't exist, your server will respond with a 404. In ASP.NET, you have a choice about how to respond to that - it's in the web.config as CustomErrors. Turn that on, then redirect to a fancy 404 page (maybe you already do). The fancy 404 page, then, could be checking the requested querystring (which gets passed over to the custom error page as yet another querystring) to see if it's a valid redirect, lives in your database, etc. Just do a Response.Redirect() from there.

这可以让你维护一些逻辑,将这些关系存储在数据库中,而不是将它们全部写入过滤器配置。

That lets you maintain some logic, store these relationships in a database, and not write them all out to a filter config.

这篇关于使用Querystring重写/重定向URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆