Point subdomain to root of main site on cPanel - cpanel

I need to point a subdomain (sub.example.com) to the same root as the main site (example.com). So when someone accesses sub.example.com, the same homepage is displayed.
I tried creating the subdomain and pointing it to /public_html instead of /public_html/sub, but if I access sub.example.com I get redirected to sub.example.com/cgi-sys/defaultwebpage.cgi, but if I access sub.example.com/index.php I get the right homepage.
My question is, how to properly point a subdomain to the root of the main site on cPanel?
Any help is very much appreciated.

cPanel redirect to "cgi-sys/defaultwebpage.cgi" when there is not index page present in document root. But as you said sub.example.com/index.php is working so I am not. Add the below lines in .htaccess in public_html folder and give it a try again. Create the .htaccess file if it's not present
DirectoryIndex index.php

Other option is to put a redirect for the subdomain with the domains homepage url
http://docs.cpanel.net/twiki/bin/view/AllDocumentation/CpanelDocs/ReDirects

Related

Subdomain is redirecting to primary domain files

I have created a subdomain(development.domain.com.np). Everytime when i hit the subdomain url it shows subdomain link but uses primary domain index.php file.
But when remove index.php file from my subdomain and replace it with index.html it works fine.
I am not able to figure out what is causing this.
I have checked redirects and logs but everything seems fine.
Do I have to add anything in htaccess file?. Any help is highly appreciated. Thank you.
You need to create 2 virtualhosts in your apache configuration pointing to 2 different documentRoots: one for each virtualhost. This way each virtualhost will handle just one domain: the documentRoot in each virtulahost will show only the files related to that specific domain.

Apache: How can i redirect all sites on the server to an URL?

I have a VPS based Centos/cPanel-WHM. I wanna redirect all sites (including all pages & subdomains) on the server to one URL. How can i do this?
create .htaccess file in every website DocumentRoot dir which you want to redirect
# This allows you to redirect your entire website to any other domain
Redirect 301 / http://exampledomain-redirect.com/
At webserver layer (change the .htaccess), you could issue 301 redirects for any requests to your sites to new URL
OR
you could inject javascript (through your web layer) or your code layout framework OR manually
at the head of the page to complete a redirect.
OR
if your domains point to different hosting.. you could upate their NS to point to your new location and do 1 OR 2
.htaccess is the best way, Otherwise change the document root for each site.

Subdomain redirect to cgi-sys/defaultwebpage.cgi

I'm having this problem: when I access the URL "bobbabr.org", it's normal, but when I access the subdomain "ibobba.bobbabr.org", I'm redirected to "/cgi-sys/defaultwebpage.cgi".
I already try to delete the .htacess, re-create the subdomain and the folder, nothing worked.
I have two .htacess on the host: one in the root (/public_html) and other in the subdomain folder (/public_html/ibobba).
I don't know what to do. Any tips?
Try clearing your cache. Sometimes the problem is browser-specific.

Apache cross domain 404

I want to make apache to always open up a signle page for 404 errors from all subdomains.
The problem is that my subdomains are located in subfolders in public_html, and thus have a different root path.
For example the main domain this works quite well:
ErrorDocument 404 /Error/404.html
The Error folder and the main domain are located in public_html respectively.
However for the forum subdomain, located in public_html/forum/ the above root path does not, and it actually looks for public_html/forum/Error/404.html which doesn't exist.
I tried to rewrite rule for the forum folder, but it didn't work out either:
ErrorDocument 404 /../Error/404.html
Seems, it cannot go below the root folder for some reason.
Any ideas how can I refer to the same page from the main and the subdomain alike, without triggering redirects? (eg: http://mysite/Error/404.html would accomplish this, but would also change the url address of the page which I don't want)
Seems, it cannot go below the root folder for some reason.
Because being able to traverse above the document root is a very, very serious security risk. If your webserver gets compromised, people would be able to serve all kinds of files anywhere on your entire server.
If you have access to server config you can setup aliases for the /Error folder. For example, in your forum subdomain's vhost config, you can add:
Alias /Error /path/to/public_html/Error/
This way, when you go to http://forum.yourdomain.com/Error/404.html you'd actually be looking at http://main.yourdomain.com/Error/404.html. Then you can just use:
ErrorDocument 404 /Error/404.html
like normal in your forum subdomain.
But if you don't have access to your server/vhost config, you'll need to use mod_proxy and mod_rewrite. So in the htaccess file in public_html/forum/, add these to the top:
RewriteEngine On
RewriteRule ^Error/(.*)$ http://main.yourdomain.com/Error/$1 [L,P]

What's causing this forced redirect?

I do not have root access to the site site.com but I have access to a subdomain me.site.com
I add an index.php (or any file and or folder for that matter) to the root folder (public_html) of this subdomain but everytime I try to go to me.site.com/index.php I get redirected to www.site.com
The .htaccess file in this subdomain is currently blank.
Why might this be happening?
Thanks!
I'm afraid that .htaccess in subdomain folder can't override the .htaccess in root, and at the moment the .htaccess in your root folder is current affecting the subdomain, in which it redirects all visits to the subdomain to root. Imagine that .htaccess from your subdomain folder redirect visits to the directory itself and .htaccess from root also redirects visits to subdomain back to the root itself, that's gonna be a mess.
Well, that's what I think about it in my opinion. Have you tried contacting the one who own root folder to consider about this?