Redirect website with WWW and without WWW using .htaccess


Redirect without WWW 

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.aviweb\.com [NC]
RewriteRule ^(.*)$ http://aviweb.com/$1 [L,R=301]



Redirect with WWW 

RewriteEngine on
RewriteCond %{HTTP_HOST} ^aviweb\.com [NC]
RewriteRule ^(.*)$ http://www.aviweb.com/$1 [L,R=301]


Custom post type redirect in WordPress

add_action( 'template_redirect', 'aviweb_redirect_post_type' );
function aviweb_redirect_post_type() {
	$queried_post_type = get_query_var('post_type');
	if ( is_single() && 'custom_post' ==  $queried_post_type ) {
		$redirection_url = get_site_url() . '/custom_page';
		wp_redirect( $redirection_url, 301 );
	exit;
	}		
}