Mobile app version of vmapp.org
Login or Join
Pierce454

: Redirect subdomain to www I created a subdomain in cPanel and set it to redirect to the www version of my site. The redirecting works insofar as redirecting subdomain.example.com to www.example.com.

@Pierce454

Posted in: #Cpanel #Htaccess #Redirects #Subdomain

I created a subdomain in cPanel and set it to redirect to the www version of my site. The redirecting works insofar as redirecting subdomain.example.com to example.com.

But when a visitor tries to go to subdomain.example.com/file1, he is taken to a 404 page instead of example.com/file1.

How do I fix this?

Edit: This is the .htaccess that cPanel has created in the subdomain's directory (which btw is just public_htmlsubdomain

RewriteEngine on

RewriteCond %{HTTP_HOST} ^subdomain.example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.subdomain.example.com$
RewriteRule ^/?$ "http://www.example.com/" [R=301,L]

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Pierce454

1 Comments

Sorted by latest first Latest Oldest Best

 

@Jamie184

Turn off the cPanel redirect. Not sure what it is doing or how. But clearly it is not working right.

Create an .htaccess file in your sub-domain root directory with:

RewriteEngine on
RewriteRule ^(.*)$ www.example.com/ [L,R=301]


...in it. Obviously change example.com to your domain name. That should do what you want.

If you do not know where that directory is, cPanel should be able to tell you. I do not use cPanel so I could not walk you through this. Sorry. But if you cannot find it and have shell access to your server, you can look at /etc/apache2/sites-available/. Your configuration file should be obvious. You can get the directory location from that. If sites-available is not there, then look at /etc/apache2/ for apache2.conf or httpd.conf. It should be defined there. Different Apache installs either use the new format (sites-available) for virtual hosting or the old format for single site hosting which can also be used for virtual hosting with more work. For example Ubuntu uses the new format and Redhat uses the old.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme