With reference of answer by @TomBrossman here

I need to redirect all domain versions to my default domain i.e. https://example.com/. By all domain versions I mean http://www, http:// and https://www. I don't want htaccess redirect.

When I add Redirect line in httpd.conf. cPanel removes it. After some research I came to know that I've 3 options to change in cPanel environment.

  1. Pre Main Include
  2. Pre Virtual Host Include
  3. Post Virtual Host Include

    <VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    **Redirect 301 / https://example.com/ (Cpanel Remove this)**

Is there anyway I can redirect my domain with VirtualHost on cPanel? Or even by domain registrar or DNS setting?

I have a VPS with root access.

  • 1
    "or even domain or DNS level" - What do you mean by domain level? And you can't "redirect" with DNS. – MrWhite Dec 21 '16 at 23:04
  • I meant domain registrar or DNS setting. There might be another way i am unaware of. – muhammad usman Dec 22 '16 at 5:02
  • 1
    Sorry, I don't know much about these cPanel features, but adding code to the "Post Virtual Host Include" doesn't seem like the correct way to add VirtualHosts?? But if you have "a VPS with root access", can you not edit the necessary files directly? (Btw, you can't do the required redirection from your domain register or in DNS.) – MrWhite Dec 22 '16 at 20:27

Have you used the options in the 'Redirects' section of cPanel? You can add a Permanent(301) redirect for the www. More info can be found here...

  • 1
    This will add (mod_rewrite) redirects to the .htaccess file, not the main server config, which would seem to be the OP's preference. (Although personally I would steer well clear of the redirects section in cPanel. Unfortunately, the code that cPanel generates is rather poor IMO and can at times break your site - particularly if you have existing directives.) – MrWhite Dec 22 '16 at 22:19
  • Thanks for your answer @Julaine but w3dk is right. – muhammad usman Dec 23 '16 at 5:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.