将子域作为参数传递 [英] Pass subdomain as parameter
问题描述
我是ISAPI_Rewrite&的新手.我很讨厌正则表达式.我需要 ISAPI_Rewrite 的重写规则,该规则将删除子域并将其作为参数传递.例如:
I'm new to ISAPI_Rewrite & I'm terrible with regular expressions. I'm in need of a rewrite rule for ISAPI_Rewrite that will remove the subdomain and pass it as a parameter. For example:
mysubdomain.mydomain.com
应该成为
mydomain.com/Landing.aspx?ID=mysubdomain
我已经找到了一个 正则表达式,该正则表达式似乎与除www
之外的所有子域都匹配,但是我不确定如何将子域作为参数传递,如上面的示例所示.
I've found a regex that seems to match all subdomains except www
, but I'm not sure how to then pass the subdomain as a parameter as the example above shows.
^((?:(?!www).)*)
任何帮助将不胜感激.
注意::我使用的是ISAPI_Rewrite的完整版,因此此规则将在网站级别执行.
Note: I'm using the full version of ISAPI_Rewrite so this rule will be at the site-level.
全局规则:
# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.89
#Disable extentionless processing for ASP.Net v 4.0
RewriteRule (.*)eurl.axd/.* $1
# Don't rewrite urls that are inside the assets folder or have the following extentions
RewriteRule ((^/Assets/.*)|(.*\.axd.*)|(.*\.asmx.*)|(.*\.png.*)) $1 [NC,L]
#Rewrite URL, pass last portion of URL to Landing.aspx + purl
RewriteRule (.*) $2/landing.aspx\?id=$1 [NC]
推荐答案
类似的方法可能对您有用:
Something like this may work for you:
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} ([^.]+)(?<!^www)(\.|$) [NC]
RewriteRule ^ Landing.aspx?ID=%1 [L,QSA]
PS:您的全局规则似乎与我的上述规则相冲突.因此,我建议您使用这样的全局规则来避免冲突:
PS: Looks like your global rule is in conflict with above rule of mine. I would therefore suggest you to have your global rule like this to avoid conflict:
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !mydomain\.com$ [NC]
RewriteRule ^(.*)$ landing.aspx?id=$1 [L]
这篇关于将子域作为参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!