在匹配的RewriteCond上停止执行Mod_Rewrite

时间:2023-01-13 11:19:35

I am running the free version of Helicon ISAPI Rewrite on IIS and have several sites running through the same set of rewrite rules. Up 'til now this has been fine as all the rules have applied to all the sites. I have recently added a new site which I don't want to run through all the rules. Is there any way to make requests to this site break out of the rule set after it's executed its own rules.

我在IIS上运行Helicon ISAPI Rewrite的免费版本,并且有几个站点运行相同的重写规则集。直到现在这已经很好,因为所有规则都适用于所有网站。我最近添加了一个新网站,我不想贯穿所有规则。在执行自己的规则后,有没有办法让对此站点的请求突破规则集。

I've tried the following with no luck; all requests to mysite.com result in a 404. I guess what I'm looking for is a rule that does nothing and is marked as the last rule to execute [L].

我试过以下没有运气;所有对mysite.com的请求都会产生404.我想我正在寻找的是一条什么都不做的规则,并被标记为执行[L]的最后一条规则。

## New site rule for mysite.com only
RewriteCond  Host:  (?:www\.)?mysite\.com
RewriteRule  /content([\w/]*)   /content.aspx?page=$1 [L]

## Break out of processing for all other requests to mysite.com
RewriteCond  Host:  (?:www\.)?mysite\.com
RewriteRule (.*) - [L]

## Rules for all other sites
RewriteRule ^/([^\.\?]+)/?(\?.*)?$ /$1.aspx$2 [L]
...

4 个解决方案

#1


9  

I've done something similar, to stop mod_rewrite on a WebDAV folder:

我做了类似的事情,在WebDAV文件夹上停止mod_rewrite:

# stop processing if we're in the webdav folder
RewriteCond %{REQUEST_URI} ^/webdav [NC]
RewriteRule .* - [L]

That should work for your purposes too. If not or if you are interested in additional references, see this previous question: How do I ignore a directory in mod_rewrite?

这应该也适用于您的目的。如果没有,或者如果您对其他参考感兴趣,请参阅上一个问题:如何忽略mod_rewrite中的目录?

#2


1  

Rewrite it to itself?

把它改写成自己?

RewriteCond  Host:  (?:www\.)?mysite\.com
RewriteRule ^(.*)$ $1 [QSA,L]

#3


1  

I don't know ISAPI Rewrite syntax, but on IIRF, the "break out" rule is like this:

我不知道ISAPI重写语法,但在IIRF上,“突破”规则是这样的:

## Break out of processing for all other requests to mysite.com
RewriteCond %{SERVER_NAME}  ^(?:www\.)?mysite\.com$
RewriteRule (.*) - [L]

or

## Break out of processing for all other requests to mysite.com
RewriteCond %{HTTP_HOST}  ^(?:www\.)?mysite\.com$
RewriteRule (.*) - [L]

In each case the rule says "don't rewrite (and don't process any more rules)" and it applies when the hostname used is mysite.com or www.mysite.com. The [L] flag is the part that says "don't process any more rules" and the - replacement is the part that says "don't rewrite".

在每种情况下,规则都说“不要重写(并且不再处理任何规则)”,当使用的主机名是mysite.com或www.mysite.com时,它适用。 [L]标志是表示“不再处理任何规则”的部分,而 - 替换是表示“不重写”的部分。

#4


0  

RewriteRule ^ - [END]

  • . would be incorrect, since it requires at least 1 char
  • 。会不正确,因为它需要至少1个字符

  • .* could be less efficient IMHO
  • 。*可能效率较低恕我直言

  • L is worse than END, as it allows for additional rounds, also on internal redirects. Only END truly stops. → Details
  • L比END更差,因为它允许额外的轮次,也在内部重定向上。只有END才真正停止。 →详细信息

#1


9  

I've done something similar, to stop mod_rewrite on a WebDAV folder:

我做了类似的事情,在WebDAV文件夹上停止mod_rewrite:

# stop processing if we're in the webdav folder
RewriteCond %{REQUEST_URI} ^/webdav [NC]
RewriteRule .* - [L]

That should work for your purposes too. If not or if you are interested in additional references, see this previous question: How do I ignore a directory in mod_rewrite?

这应该也适用于您的目的。如果没有,或者如果您对其他参考感兴趣,请参阅上一个问题:如何忽略mod_rewrite中的目录?

#2


1  

Rewrite it to itself?

把它改写成自己?

RewriteCond  Host:  (?:www\.)?mysite\.com
RewriteRule ^(.*)$ $1 [QSA,L]

#3


1  

I don't know ISAPI Rewrite syntax, but on IIRF, the "break out" rule is like this:

我不知道ISAPI重写语法,但在IIRF上,“突破”规则是这样的:

## Break out of processing for all other requests to mysite.com
RewriteCond %{SERVER_NAME}  ^(?:www\.)?mysite\.com$
RewriteRule (.*) - [L]

or

## Break out of processing for all other requests to mysite.com
RewriteCond %{HTTP_HOST}  ^(?:www\.)?mysite\.com$
RewriteRule (.*) - [L]

In each case the rule says "don't rewrite (and don't process any more rules)" and it applies when the hostname used is mysite.com or www.mysite.com. The [L] flag is the part that says "don't process any more rules" and the - replacement is the part that says "don't rewrite".

在每种情况下,规则都说“不要重写(并且不再处理任何规则)”,当使用的主机名是mysite.com或www.mysite.com时,它适用。 [L]标志是表示“不再处理任何规则”的部分,而 - 替换是表示“不重写”的部分。

#4


0  

RewriteRule ^ - [END]

  • . would be incorrect, since it requires at least 1 char
  • 。会不正确,因为它需要至少1个字符

  • .* could be less efficient IMHO
  • 。*可能效率较低恕我直言

  • L is worse than END, as it allows for additional rounds, also on internal redirects. Only END truly stops. → Details
  • L比END更差,因为它允许额外的轮次,也在内部重定向上。只有END才真正停止。 →详细信息