user1647020
user1647020

Reputation: 73

htaccess redirect apply to 1st level subdirectory, but ignore if it is a sub-subdirectory

I have a site with a ton of backlinks pointing to a directory /portfolio/ and subfolders therein and I want to redirect them all to the root (because some of those old sub subdirectories are gone completely) of the new directory /project-portfolio/

The problem is that there is another /portfolio/ that I don't want rewritten or redirected...it resides deeper in another subdirectory /uploads/images/portfolio/

How do I write my rewrite rule so that it applies to a top subdirectory /portfolio/ but ignores the other?

Thanks.

Upvotes: 0

Views: 102

Answers (2)

Jon Lin
Jon Lin

Reputation: 143906

In your document root, create an htaccess file and add this:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/uploads/images/portfolio
RewriteRule (^|/)portfolio(/|$) /project-portfolio/ [L,R=301]

Upvotes: 1

ChaseTheSun
ChaseTheSun

Reputation: 3840

<Directory /path/to/docroot/folder>
        Options +Indexes
</Directory>
<DirectoryMatch  /path/to/docroot/folder/(.)*/>
        Options -Indexes
</DirectoryMatch>

Upvotes: 0

Related Questions