All about htaccess redirects in wordpress

All about htaccess redirects in wordpress

 

HTTPS to HTTP domain redirect

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

 

Permanent 301 redirect your olddomain to a new  www domain?

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]

Permanent 301 redirect your old domain to new non-www domain?

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]

Redirect all links of a domain except the domain name?

Options +FollowSymlinks
RewriteEngine on

#ip to allow access
RewriteCond %{REMOTE_HOST} !^11\\.11\\.11\\.11$

#send to root
RewriteRule (.*)$ http://www.iseleyrealty.com/$1 [R=302,L]

Redirect all links of a domain except the domain name and few file path.

Now if you put a dummy html page as a demo to your root and all the related files under

/html/style.css

/html/logo.png

It will also be redirecting all files path to the newdomain.

As a modifcation you will also need to exclude this path.

Options +FollowSymlinks
RewriteEngine on

#urls to exclude
RewriteCond %{REQUEST_URI} !^/html/style.css$
RewriteCond %{REQUEST_URI} !^/html/logo.png$
RewriteCond %{REQUEST_URI} !^/$

#ip to allow access
RewriteCond %{REMOTE_HOST} !^11\\.11\\.11\\.11$

#send to root
RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]