Redirect directory (but not subdirectories) to another directory

258 views Asked by At

How do I redirect a directory to the root of a site? Provided that:

  • the root of the site is actually not the root of the domain. ex: it should redirect to 'www.example.com/website', not to 'www.example.com'

  • don't redirect subfolders. ex: it should redirect 'www.example.com/website/portfolio' to 'www.example.com/website', but it shouldn't redirect 'www.example.com/website/portfolio/project-name'.

It's a WordPress site and it's already working with the following rules:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /website/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /website/index.php [L]
</IfModule>
# END WordPress

Thanks in advance!

1

There are 1 answers

0
anubhava On BEST ANSWER

You can do:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /website/

RewriteRule ^portfolio/?$ /website/ [L,R]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /website/index.php [L]
</IfModule>