ISAPI 重写帮助重定向到子域

发布于 2024-10-21 04:29:32 字数 619 浏览 1 评论 0原文

我需要一些 ISAPI 语法帮助,我即将上线一个新站点,并希望将旧论坛存档到存档子域中。

该论坛采用 ASP 格式,目前的 URL

http://www.mywebsite .co.uk/forum/forum_posts.asp?TID=34419 http://www.mywebsite.co.uk/forum/forum_topics.asp?FID=47

我希望论坛的每个请求都被 301 重定向到:

http://archive.mywebsite.co.uk/forum/forum_posts.asp?TID=34419 http://archive.mywebsite.co.uk/forum/forum_topics.asp?FID=47

基本上论坛文件夹中带有 .asp 扩展名(带或不带查询字符串)的任何内容 - 非常感谢任何帮助。

谢谢

I need a bit of ISAPI syntax help, I am about to put live a new site and want to archive the old forum onto an archive sub domain.

The forum is in ASP and currently has this URL

http://www.mywebsite.co.uk/forum/forum_posts.asp?TID=34419
http://www.mywebsite.co.uk/forum/forum_topics.asp?FID=47

I want every request for the forum to be 301 redirected to:

http://archive.mywebsite.co.uk/forum/forum_posts.asp?TID=34419
http://archive.mywebsite.co.uk/forum/forum_topics.asp?FID=47

Basically anything with in the forum folder with .asp extension with or without a query string - Any help greatly appreciated.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

棒棒糖 2024-10-28 04:29:32

对于将网址重定向到子域,自您提出问题以来已经过去了几个月,但这也许仍然会有帮助。

假设您使用的是 isapi_rewrite v3,请尝试以下操作:

RewriteCond %{HTTP:Host} ^www\.
RewriteRule ^/forum/(.*\.asp)$ http://archive.mywebsite.co.uk/forum/$1 [NC,R=301]

第一行查找以 www 开头的主机。 (带有尾随点)。这可以确保您不会出现无限循环,将存档重定向到自身。尾随点是挑剔的只做 www,而不是其他像 www2。

第二行查找 /forum/,然后捕获 (...) 任何字符 .* 以及文字点和 asp \ .asp,以 url $ 结尾,

然后转到 /forum/ 文件夹中的子域(因为 /forum/ 未被捕获,我们需要重复),以及捕获的 URL 的整个其余部分 $1

NC 表示不区分大小写,因此所有这些都可以混合大小写。
R=301 表示重定向,并使其成为永久 301 重定向,因为这不是临时的。

在 v3 规则中,查询字符串参数的处理完全与规则分开,因此您无需在此处执行任何操作。如果没有参数,那么这有效。如果有参数,它们将按照您上面的问题传递。

这会忽略 http 与 https。它将重定向到 http,因此如果原始是 https,可能会出现浏览器警告。有很多方法可以处理它,但我不想弄乱基本答案。

在我看来,将域本身包含在重写规则中总是有点奇怪,因为您可能想移动它。您可以在第一行中捕获主机的其余部分,并在第二行中使用它。

RewriteCond %{HTTP:Host} ^www\.(.*)$
RewriteRule ^/forum/(.*\.asp)$ http://archive.%1/forum/$1 [NC,R=301]

这与上面类似,除了捕获 www-点之后的主机,到行尾 (.*)$ 我不确定这里是否需要 $,但是它明确表明我们想要这一切。

RewriteCond 捕获的数据以百分号编号,因此重写规则中的 %1 会替换子域后面的主机,而 $1 仍然表示替换捕获的 ...asp url。

For redirecting a url to a subdomain, it has been a few months since your question, but maybe this will still help.

Assuming you're using isapi_rewrite v3, try this:

RewriteCond %{HTTP:Host} ^www\.
RewriteRule ^/forum/(.*\.asp)$ http://archive.mywebsite.co.uk/forum/$1 [NC,R=301]

The first line looks for host beginning with www. (with the trailing dot). This makes sure you don't get an infinite loop, redirecting archive to itself. The trailing dot is being picky at doing only www, and not others like www2.

The second line looks for /forum/, then captures (...) any characters .* and literal dot and asp \.asp, ending the url $

It then goes to your subdomain in the /forum/ folder (since /forum/ wasn't captured, we need to repeat it), and the entire rest of the url that was captured $1.

The NC means not case-sensitive, so all this can be mixed upper and lower case.
The R=301 means redirect, and make it a permanent 301 redirect since this isn't temporary.

In the v3 rules, querystring parameters are handled entirely separately from the rules, so you don't have to do anything at all here. If there are no parameters, then this works. If there are parameters, they are passed on as in your question above.

This ignores http vs https. It will redirect to http, so if the original was https, there will probably be a browser warning. There are ways to handle it, but I didn't want to clutter the basic answer.

Having the domain itself in the rewrite rule is always a little weird looking to me, since you might want to move it around. You can capture the rest of the host in the first line, and use it in the second.

RewriteCond %{HTTP:Host} ^www\.(.*)$
RewriteRule ^/forum/(.*\.asp)$ http://archive.%1/forum/$1 [NC,R=301]

This is similar to above, with the addition that the host after the www-dot is captured, to the end of the line (.*)$ I'm not sure the $ is required here, but it makes it explicit we want it all.

RewriteCond captures are numbered with a percent sign, so %1 in the rewrite rule substitutes the host after the subdomain, and $1 still means substituting the captured ...asp url.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文