Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect site with .htaccess but exclude one folder

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?

like image 542
PaulAdamDavis Avatar asked Aug 05 '10 10:08

PaulAdamDavis


People also ask

Does .htaccess do redirect?

Use a 301 redirect . htaccess to point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the "example.com" domain.

What is a 301 .htaccess redirect?

What Is a 301 Redirect? A 301 redirect is a permanent redirect. When a user tries to access an old URL, the server sends their browser the 301-Permanently Moved status code and sends them to another page. This is useful for site owners and users because it means they are directed to the next most relevant page.

Should I enable 301 .htaccess redirect?

Because the WordPress 301 redirect is not always reliable, we recommend issuing the 301 redirect via your . htaccess file. Another benefit is that the . htaccess redirect is slightly faster than redirecting via PHP, because it is loaded even before the rest of the page.


1 Answers

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.

like image 126
Gumbo Avatar answered Sep 30 '22 12:09

Gumbo