Hi Everyone,

This article can help you to get some insight on redirection using Apache configuration file ie .htaccess.

Before going further, please go through this article to better understand about .htaccess file on WordPress.

The logic here is to redirect whole domain except any link that consists of `​wp-admin` and other document files like .css, .js, image extension like: .jpeg, .png. jpg.

Copy below code, clean up of .htacces file and paste this copied code on to your .htaccess file.

# BEGIN WordPress

RewriteEngine On
RewriteRule ^(.*)wp-admin(.*)$ - [L]
RewriteRule ^(.*)wp-login.php(.*)$ - [L]
RewriteRule ^(.*).js(.*)$ - [L]
RewriteRule ^(.*).css(.*)$ - [L]
RewriteRule ^(.*).png(.*)$ - [L]
RewriteRule ^(.*).jpeg(.*)$ - [L]
RewriteRule ^(.*).jpg(.*)$ - [L]
RewriteRule ^(.*)$ https://www.levity.video/home [NC]

# END WordPress

Quick overview of above code.

RewriteRule: Defines rules for the rewriting engine

^(.*)wp-admin(.*)$: a pattern that will be matched with the current  URL. If match found apache will proceed substitution which is dash – in our case.

-: This dash tell apache server to not apply any substitution to the URL that matches with the pattern.

[L]: Stop the rewriting process immediately and don’t apply any more rules

^(.*)$: Pattern that matches any character on URL and moves to substitution which is https://xxx.redirectlinke.com

[NC] :Makes the pattern comparison case-insensitive.

To know more on RewriteRule please visit this  article.

Note: Hey guys, Please let me know if there is any optimised code for restricting document file. I had used individual line for each document files.

I hope this may help anyone struggling for redirection.


Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: