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?
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 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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With