开发者

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.

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?FI开发者_运维问答D=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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜