Few days before I was stuck in issue of .htaccess redirection with wordpress. I found solution after many hours efforts and want to post it to others that if any other get stuck in such condition then may be he will found me post and also I get another encounter then this post will help me and save time. If you have one hosting and many domains  in one hosting and u want that all links redirect to one domain then what to do. We can do it from .htaccess so we have to write it in such a way that the request from every domain get redirected to the main domain and requests from main domain works normally. See the .htaccess below which can do this job.

 

RewriteOptions inherit

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# New code to redirect from domainone.net to maindomain.com
# Permanent redirect for caching purposes, also include the query string
RewriteCond %{HTTP_HOST} ^domainone\.net
RewriteRule (.*) http://maindomain.com/$1 [R=permanent,QSA,L]

# New code to redirect from www.domainone.net to www.maindomain.com
RewriteCond %{HTTP_HOST} ^www\.domainone\.net
RewriteRule (.*) http://www.maindomain.com/$1 [R=permanent,QSA,L]

# New code to redirect from domainone.com to maindomain.com
# Permanent redirect for caching purposes, also include the query string
RewriteCond %{HTTP_HOST} ^domainone\.com
RewriteRule (.*) http://maindomain.com/$1 [R=permanent,QSA,L]

# New code to redirect from www.domainone.com to www.maindomain.com
RewriteCond %{HTTP_HOST} ^www\.domainone\.com
RewriteRule (.*) http://www.maindomain.com/$1 [R=permanent,QSA,L]

# New code to redirect from domainone.pk to maindomain.com
# Permanent redirect for caching purposes, also include the query string
RewriteCond %{HTTP_HOST} ^domainone\.pk
RewriteRule (.*) http://maindomain.com/$1 [R=permanent,QSA,L]

# New code to redirect from www.domainone.pk to www.maindomain.com
RewriteCond %{HTTP_HOST} ^www\.domainone\.pk
RewriteRule (.*) http://www.maindomain.com/$1 [R=permanent,QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *