Domain redirection with virtualhost on cpanel environment?

Discussion in 'Apache' started by deemasfashion, Dec 21, 2016.

  1. #1
    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)
    ...
    </VirtualHost>
    Code (markup):

    Is there any way i can redirect my domain with virtualhost or at domain registrar or VPS level?

    I have Managed VPS with root access but i don't have good server knowledge.

     
    deemasfashion, Dec 21, 2016 IP
  2. clusterednet

    clusterednet Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    cPanel will remove this each time apache is rebuild.
    You should have line in httpd.conf like :

    # To customize this VirtualHost use an include file at the following location
    Use that to put your redirect in, or you can put your redirect in like above and then run:

    /usr/local/cpanel/bin/apache_conf_distiller --update

    John
     
    clusterednet, Jan 3, 2017 IP