Page 1 of 1
Redirection from maindomain.subdomain to www.subdomain.com?
Posted: Sun May 11, 2014 3:53 pm
by WGH
I have two separate websites, not related. one is in the public_html folder and works fine at
www.maindomain.com. I have added a new website in a subfolder of the public_html folder.
I am using cpanel.
Presently I can find my second website by typing
www.maindomain.subdomain.com. This is not ideal. I need the second new web site URL to be
www.subdomain.com.
How do i do this? I see from forum discussions that I will need to modify the htaccess files in both the public_html folder and subfolder. All the posts cover redirecting the subdomain url. I need to hide/remove the maindomain part of the URL.
Re: Redirection from maindomain.subdomain to www.subdomain.c
Posted: Sun May 11, 2014 4:08 pm
by dhuelsmann
Add the following to your .htaccess in your maindomain after the rewrite engine is turned on.
Code: Select all
RewriteCond %{HTTP_HOST} ^(www\.)?subdomain\.maindomain\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^!www\.subdomain\.com [NC]
RewriteRule ^(.*)$ http://www.subdomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^subdomain.com [NC]
RewriteRule ^(.*)$ http://www.subdomain.com/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/subdomain($|/.*$)
RewriteRule ^.* http://www.subdomain.com%1 [R=301,L]
Re: Redirection from maindomain.subdomain to www.subdomain.c
Posted: Sun May 11, 2014 6:42 pm
by WGH
Hi Dave. Thanks for the time and effort.
I entered this into a blank .htaccess file in my root public_html folder.
Where: hedgehoglane.co.za is in the root public_html folder and johngiclarke.co.za is in the subfolder off the public_html folder.
# mod_rewrite in use
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?johngiclarke\.co\.za\.hedgehoglane\.co\.za [NC,OR]
RewriteCond %{HTTP_HOST} ^!www\.johngiclarke\.co\.za [NC]
RewriteRule ^(.*)$
http://www.johngiclarke.co.za/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^johngiclarke.co.za [NC]
RewriteRule ^(.*)$
http://www.johngiclarke.co.za/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/johngiclarke($|/.*$)
RewriteRule ^.* http://www.johngiclarke.co.za%1 [R=301,L]
if i now enter the following into my url bar
www.johngiclarke.co.za i get the typical "Server not found" message.
What do i need to do to get this working? Have I made an error above?
Re: Redirection from maindomain.subdomain to www.subdomain.c
Posted: Sun May 11, 2014 6:56 pm
by dhuelsmann
Did you create an add-on domain in your cpanel? Did you register your new domain and have it point to your host's DNS servers?
Re: Redirection from maindomain.subdomain to www.subdomain.c
Posted: Sun May 11, 2014 7:03 pm
by WGH
Hi Dave
Yes to all.
if I enter
www.hedgehoglane.co.za/johngiclarke.co.za I get a web page. I just want to get rid of the hedgehoglane.co.za part of the url.
IOW. i just want to enter
www.johngiclarke.co.za and go directly to the correct web page
Re: Redirection from maindomain.subdomain to www.subdomain.c
Posted: Sun May 11, 2014 7:19 pm
by dhuelsmann
Try this with the minor change of removing the slashes between .co and .za
Code: Select all
# mod_rewrite in use
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?johngiclarke\.co.za\.hedgehoglane\.co.za [NC,OR]
RewriteCond %{HTTP_HOST} ^!www\.johngiclarke\.co.za [NC]
RewriteRule ^(.*)$ http://www.johngiclarke.co.za/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^johngiclarke.co.za [NC]
RewriteRule ^(.*)$ http://www.johngiclarke.co.za/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/johngiclarke($|/.*$)
RewriteRule ^.* http://www.johngiclarke.co.za%1 [R=301,L]
Re: Redirection from maindomain.subdomain to www.subdomain.c
Posted: Sun May 11, 2014 7:30 pm
by WGH
Hi Dave
Nope. No change. Still get "server error"
Re: Redirection from maindomain.subdomain to www.subdomain.c
Posted: Sun May 11, 2014 8:07 pm
by dhuelsmann
One more try then I am out of ideas if it doesn't work.
Code: Select all
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ hedgehoglane.co.za$ [OR]
RewriteCond %{HTTP_HOST} ^ www.hedgehoglane.co.za$
RewriteRule ^ johngiclarke.co.za/?(.*)$ "http\:\/\/www\.hedgehoglane\.co\.za\/$1" [R=301,L]
RewriteCond %{HTTP_HOST} ^ johngiclarke.co.za.hedgehoglane.co.za$ [OR]
RewriteCond %{HTTP_HOST} ^ www.johngiclarke.co.za.hedgehoglane.co.za$
RewriteRule ^/?(.*)$ "http\:\/\/www\.hedgehoglane.co.za\.co\.za\/$1" [R=301,L]
Re: Redirection from maindomain.subdomain to www.subdomain.c
Posted: Sun May 11, 2014 8:11 pm
by dhuelsmann
If the above doesn't work try your CPanel url redirect. It might do it better than me, who knows?
Re: Redirection from maindomain.subdomain to www.subdomain.c
Posted: Sun May 11, 2014 8:20 pm
by WGH
Hi Dave - thanks for all the effort!
The last code crashed the main website.
I did try the cpanel redirect panel without any joy prior to posting.
Re: Redirection from maindomain.subdomain to www.subdomain.c
Posted: Sun May 11, 2014 8:34 pm
by dhuelsmann
Well darn!