views:

144

answers:

1

I am trying to write a rule to redirect some but not all of the content of a certain folder:

  • ^folder1/ any .html files
  • ^folder1/blackberry
  • ^folder1/content
  • ^folder1/data
  • ^folder1/images
  • ^folder1/docs

I need to use RewriteRule to send everything except ^folder1/blackberry to another site (eg, http://somedomain.com/main.html) and I'm sure there must a way to do this with regular expressions but I don't (yet) know how :-)

A: 

Use a rule to catch everything and exclude the exceptions with a RewriteCond directive:

RewriteCond %{REQUEST_URI} !^/folder1/blackberry$
RewriteRule ^folder1/ http://sub.example.com/main.html [L,R=301]

This rule redirects every request with a URL path that starts with /folder1/ except /folder1/blackberry externally to http://sub.example.com/main.html.

Gumbo
Sweet. I just changed it toRewriteCond %{REQUEST_URI} !^/folder1/blackberry/$so that the blackberry folder doesn't redirect. Without the end slash, it did still redirect that folder, although subfolders of blackberry were fine. Thanks so much.