Reputation: 1051
I'm trying to redirect all pages to the homepage except the ones who are in a specific url. So for clarification redirect all pages to the root expect www.ourwebsite.com/mydir/link1 All the pages in mydir should show up but if someone goes to mydir/ they should redirect to home.
I'm using wordpress so there is a .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ / [R=301,L] // Redirects all to homepage
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
So this should redirect all pages to homepage but now when someone types /mydir/link1 or /mydir/link2 etc they shouldn't be redirected
Upvotes: 1
Views: 134
Reputation: 786091
You can add a condition for exceptions:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} !/(dist/|mydir/(link1|link2)) [NC]
RewriteRule . / [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
Remember to clear your browser cache before testing this redirect rule.
Upvotes: 1