Forum Moderators: phranque

Message Too Old, No Replies

Addon Domain Redirect ?

         

leko3

8:26 am on Jun 2, 2015 (gmt 0)

10+ Year Member



I have an addon domain to my main hosting account. For example purposes my addon and main domain are: addonsite.com / main.com

Problem is cPanel subdomains are created as part of cPanel's structure and are required. Therefore my addon domain can be accessed in 2 ways:
www.addonsite.com
www.addonsite.main.com

My goal is to redirect www.addonsite.main.com to www.addonsite.com. Reason is because I want to keep my main domain completely separate and prevent someone and google from accidentally discovering my addon site through the main site because of 1. SEO problems and 2. It seems unprofessional.

My webhost said, "You could add .htaccess instructions in the addonsite's directory to specify that if the request domain is not addonsite, it will redirect to addonsite.com" But after googling, I still don't know how to turn this into htaccess code.

Below are my questions and htaccess file:

1. How do you redirect www.addonsite.main.com to www.addonsite.com ? Where would I paste this code in my htaccess file below?

2. For my main domain I had htaccess code for the below, how do you use the below code for www.addonsite.main.com ? Do I simply swap domains?

# Redirect index.html and index.php
RewriteCond %{THE_REQUEST} [A-Z]{3,9}\ /(([^/]+/)*)index\.(html|php)
RewriteRule index\.(html|php) http://www.main.com/%1 [R=301,L]

# Force Trailing Slash
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.main.com/$1/ [R=301,L]

# Domain-name canonicalization redirect
RewriteCond %{HTTP_HOST} !^(www\.main\.com)?$ [NC]
RewriteRule (.*) http://www.main.com/$1 [R=301,L]



My complete htaccess file:

Options -Indexes

<files wp-config.php>
Order allow,deny
Deny from all
</files>

<files error_log>
Order allow,deny
Deny from all
</files>

RewriteEngine On
RewriteBase /

# Redirect index.html and index.php
RewriteCond %{THE_REQUEST} [A-Z]{3,9}\ /(([^/]+/)*)index\.(html|php)
RewriteRule index\.(html|php) http://www.main.com/%1 [R=301,L]

# Force Trailing Slash
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.main.com/$1/ [R=301,L]

# Domain-name canonicalization redirect
RewriteCond %{HTTP_HOST} !^(www\.main\.com)?$ [NC]
RewriteRule (.*) http://www.main.com/$1 [R=301,L]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

phranque

11:08 am on Jun 2, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, leko3!


before your general "Domain-name canonicalization redirect", insert a more specific ruleset to handle the addonsite subdomain redirect.