Redirect subdomain to www

Redirect subdomain to www - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the Redirect subdomain to www error on your web browser. Problem :


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.



But when a visitor tries to go to subdomain.example.com/file1, he is taken to a 404 page instead of www.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]

Solution :

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 ^(.*)$ http://www.example.com/$1 [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.


We hope that this article has helped you resolve the htaccess, redirects, subdomain error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How do I redirect traffic only if being accessed from a specific port?

DNS entry to redirect constant url to changing directory name

How to redirect to any domain [duplicate]