Reputation: 341
I am trying to redirect all visits to a specific sub-folder with a few exceptions.
This is the URL I am trying to redirect:
I would like any hits to anything under that URL to be redirected to the following URL:
Except, I don't want to redirect these URLs:
I have tried to do the following within my .htaccess file but it does not seem to deal with the exceptions:
RewriteCond %{REQUEST_URI} !^/my-sub-folder/my-special-folder(/.*)?$ [OR]
RewriteCond %{REQUEST_URI} !^/my-sub-folder/wp-admin(/.*)?$
RewriteCond %{REQUEST_URI} ^/my-sub-folder(/.*)?$
RewriteRule ^(.*)$ /news/category/my-new-sub-folder/ [R=301,L]
What am I doing wrong or is there a better way?
Thanks
Upvotes: 1
Views: 1072
Reputation: 24448
It's because you are using OR
in the conditions you need to include all the conditions. Try this rule.
RewriteCond %{REQUEST_URI} !^/my-sub-folder/my-special-folder/? [NC]
RewriteCond %{REQUEST_URI} !^/my-sub-folder/wp-admin/? [NC]
RewriteCond %{REQUEST_URI} ^/my-sub-folder/?
RewriteRule ^(.*)$ /news/category/my-new-sub-folder/ [R=301,L]
Upvotes: 1
Reputation: 1030
Well you tagged it Wordpress, so you could use the Wordpress rewrite API instead of manually adding htaccess rules. Here is the codex: http://codex.wordpress.org/Rewrite_API/add_rewrite_rule Then put the rules in a plugin or your theme's functions.php file.
Upvotes: 0