Stop Mod_Rewrite execution matching RewriteCond

I run the free version of Helicon ISAPI Rewrite in IIS and have several sites running through the same set of rewrite rules. So far, this has been great, since all the rules applied to all sites. I recently added a new site that I do not want to use in all the rules. Is there a way to make requests to this site break out of the ruleset after it has completed its own rules.

I tried the following with no luck; all requests to mysite.com lead to 404. I assume that I am looking for a rule that does nothing and is marked as the last rule to execute [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] ... 
+6
mod rewrite
source share
4 answers

I did something similar to stop mod_rewrite in the WebDAV folder:

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

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

+9
source share

Rewrite it yourself?

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

I don’t know the ISAPI Rewrite syntax, but on IIRF the “break out” rule looks like this:

 ## 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 reads: “Do not rewrite (and do not process more rules),” and this applies when the hostname used is mysite.com or www.mysite.com. The [L] flag is the part that says: “Don't process more rules”, and the “replacement” is the part that says “don't rewrite”.

+1
source share

RewriteRule ^ - [END]

  • . will be wrong since it requires at least 1 char
  • .* may be less effective IMHO
  • L is worse than END, as it allows for extra rounds as well as in internal redirects. Only END really stops. → Read more
0
source share

All Articles