简体   繁体   English

重定向到子域的ISAPI重写帮助

[英]ISAPI Rewrite Help With Redirect To Sub Domain

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. 我需要一些ISAPI语法帮助,我将启用一个新站点,并希望将旧论坛存档到存档子域中。

The forum is in ASP and currently has this URL 该论坛位于ASP中,当前具有此URL

http://www.mywebsite.co.uk/forum/forum_posts.asp?TID=34419 http://www.mywebsite.co.uk/forum/forum_topics.asp?FID=47 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: 我希望将对论坛的每个请求重定向到301:

http://archive.mywebsite.co.uk/forum/forum_posts.asp?TID=34419 http://archive.mywebsite.co.uk/forum/forum_topics.asp?FID=47 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. 基本上,论坛文件夹中带有.asp扩展名且带有或不带有查询字符串的所有内容-十分感谢任何帮助。

Thanks 谢谢

For redirecting a url to a subdomain, it has been a few months since your question, but maybe this will still help. 对于将URL重定向到子域,距离您提出问题已有几个月的时间,但这也许仍会有所帮助。

Assuming you're using isapi_rewrite v3, try this: 假设您正在使用isapi_rewrite v3,请尝试以下操作:

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. 第一行查找以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. 尾随点仅在执行www时很挑剔,而对其他诸如www2而言则不然。

The second line looks for /forum/ , then captures (...) any characters .* and literal dot and asp \\.asp , ending the url $ 第二行查找/forum/ ,然后捕获(...)任何字符.*以及文字点和asp \\.asp ,以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 . 然后它将转到您在/forum/文件夹中的子域(因为未捕获/ forum /,我们需要重复此操作),并且捕获到的整个URL的其余部分为$1

The NC means not case-sensitive, so all this can be mixed upper and lower case. NC表示不区分大小写,因此所有大小写都可以混合使用。 The R=301 means redirect, and make it a permanent 301 redirect since this isn't temporary. R=301表示重定向,并使其成为永久301重定向,因为这不是临时的。

In the v3 rules, querystring parameters are handled entirely separately from the rules, so you don't have to do anything at all here. 在v3规则中,querystring参数与规则完全分开处理,因此您在这里无需执行任何操作。 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. 这将忽略http vs https。 It will redirect to http, so if the original was https, there will probably be a browser warning. 它将重定向到http,因此如果原始文件为https,则可能会出现浏览器警告。 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. 这类似于上面的内容,除了捕获www.dot之后的主机之外,在行(.*)$的末尾我不确定这里是否需要$,但是它明确表明了我们想要它所有。

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. RewriteCond捕获使用百分号编号,因此重写规则中的%1将子域替换为主机,并且$1仍表示替换捕获的... asp url。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM