Alex Rivera | Logout

Redirect site with .htaccess but exclude one folder

Asked 2010-08-05T10:59:56.407
80

I want to 301 redirect an entire website, but exclude everything in a folder called /uploads which exists in the /root directory.

I have googled for this, but didn't come up with anything, or I didn't think what I saw was right.

Can we crack this?

Edit
Report

1 Answer

97

Try this mod_rewrite rule:

RewriteEngine on
RewriteRule !^uploads($|/) http://example.com%{REQUEST_URI} [L,R=301]

This rule does match any URL path that does not begin with either /uploads or /uploads/ (leading / is missing in the pattern due to the path prefix removal when used in .htaccess files) and redirects the request to the corresponding path at example.com.

answered 2010-08-05T11:01:57.603

Your Answer