Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop Mod_Rewrite execution on matching RewriteCond

Tags:

mod-rewrite

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.

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].

## 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]
...
like image 600
Rob Bell Avatar asked Oct 23 '08 08:10

Rob Bell


People also ask

How do you check mod_rewrite is enabled or not?

Open any web browser browser and type following the URL, 'localhost/check. php'. It will display the PHP version details and Apache Configuration. In Apache Configuration, search for the Loaded Modules section, and there you will find all the modules that are enabled.

What does IfModule mod_rewrite C mean?

The <IfModule mod_rewrite. c>... </IfModule> block ensures that everything contained within that block is taken only into account if the mod_rewrite module is loaded. Otherwise you will either face a server error or all requests for URL rewriting will be ignored.

What is NC in RewriteCond?

NC|nocase. Use of the [NC] flag causes the RewriteRule to be matched in a case-insensitive manner. That is, it doesn't care whether letters appear as upper-case or lower-case in the matched URI. In the example below, any request for an image file will be proxied to your dedicated image server.

What is RewriteCond in htaccess?

htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.


1 Answers

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

# 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?

like image 153
Jay Avatar answered Sep 18 '22 13:09

Jay