Exclude a file or directory from redirecting using .htaccess rewrite rules

If you have already followed “Redirect primary domain name to directory inside / subdirectory” to redirect all URLs from website to subdirectory using redirect rules and now wanted to exclude some URLs or some directory from redirecion, append below lines after “RewriteEngine On” in .htaccess as,

[bash] RewriteEngine On RewriteRule ^(/|wp-login\.php) – [L] RewriteRule ^(/|wp-admin) – [L] [/bash]

So in above case, we tried to avoid redirection of wordpress login www.yourwebsite/wp-login.php and all urls from directory www.yourwebsite/wp-admin/
hence in general, the rule can be considered as,

[bash] RewriteRule ^(dir_name|file_name\.extension) – [L] [/bash]

here, you can add as many files or directories using OR | operator.

Leave a Comment