Include 301 redirect into apache httpd.conf – Hostgator hosting

Hostgator VPS generates apache’s httpd.conf file automatically. Therefore, any new lines you add to apache’s configuration file will be overwritten. In order to add new configuration settings we need to include a configuration. Open up your main config file /etc/httpd/conf/httpd.conf and search for a virtual host with the domain name you wish to edit. Last two lines of your virtual host should look similar to this:

# To customize this VirtualHost use an include file at the following location
#    Include "/usr/local/apache/conf/userdata/std/2/linuxcon/*.conf"

uncomment the Include line by remove leading “#”.

Next, create a directory to reflect the Include location:

# mkdir -p /usr/local/apache/conf/userdata/std/2/linuxcon/

Once your directory is created add a new .conf file. For example:

# cd /usr/local/apache/conf/userdata/std/2/linuxcon/ 
# echo "redirect 301 /some-url" > redirects.conf

Next check your apache configuration file:

# apachectl -t
Syntax OK

Once you confirm correctness of your syntax restart apache webserver:

# service httpd restart

Test your new redirect and if all goes well make sure that you do not have duplicate redirects in your main .httaccess file.

Comments and Discussions
Linux Forum